TDataSet of property Eof

TDataSet class attributes should Eof no wonder, as long as the database written, are written substantially the following logic:

cdsDatabases.First;

while not cdsDatabases.Eof do

begin

(Business logic)

cdsDatabases.Next;

end;

Such logic for granted, and we may not necessarily get to the bottom. But if you ask, when the cursor is pointing to the last record, Eof returns True or False? Most people will probably look stunned.

In fact, the answer is to look at the situation.

In official documents, lists several situations Eof to True:

Opens an empty dataset.

Calls a dataset's Last method. (Unless it is a unidirectional dataset)

Call a dataset's Next method, and the method fails because the current record is already the last row in the dataset.

Calls SetRange on an empty range or dataset.

which is:

When opening an empty data set

Last method is invoked go to the last record

Call the next method, as is currently the last record in the data set, so when the next failure

When empty data set method calls SetRange

In addition to these four cases, the situation Eof rest are false.

The above code is justified, because using the next, the first point to the last record, the method is successful, it was Eof is false, when the last record call next, the method fails, the cursor still pointing It is the last record, but this time Eof is already true of.

Guess you like

Origin blog.51cto.com/bigdata1024/2427363