Page 1 of 1

ZQuery.Delete and ZQuery.Eof

Posted: 30.03.2019, 21:46
by aehimself
Hi all,

I did my research and I know that this is not a bug in Zeos, but it Delphi's way of handling datasets but it's quite annoying and easy to fix.
You are scrolling through a dataset, deleting some records on the way:

While Not ZQuery.Eof Do
If somecondition then ZQuery.Delete
Else ZQuery.Next;

All is fine until you are trying to delete the last record, as it is not setting the Eof and somecondition might return a false positive (e.g. checking for duplicates) and start deleting records you don't want to.

The following workaround works:

Procedure TMyOwnSQLTable.Delete;
Var
islast: Boolean;
Begin
SQLTable.Next;
islast := SQLTable.Eof;
If Not islast Then SQLTable.Prior;
SQLTable.Delete;
If islast Then SQLTable.Next;
End;

So my question is if this is a well-known issue in Delphi, how come it is not fixed yet? Or am I missing something and deleting the last record should not set Eof? If this is the case, can anyone explain why?

Cheers!