Edit is inserting when no records exist

(tobygroves) #1

Found this strange issue today.

If you have an open TDAMemDataTable which has no records, and you call Edit, it actually inserts a new record and the table is then in dsInsert state.

Admittedly my fault for trying to edit a record which didn’t exist but I’d expect Edit to throw an exception in this instance, not just quietly decide to insert instead.

(EvgenyK) #2


this is standard TDataSet behavior:

procedure TDataSet.Edit;
  if not (State in [dsEdit, dsInsert]) then
    if FRecordCount = 0 then Insert else  //<<< look at Insert here

(tobygroves) #3

Ah ok, I never realised that