Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADO DataSet use EOF or IsEmpty?

Tags:

delphi

ado

The majority of my code for accessing a Stored Procedure dataset (MS SQL Server, forward-only, readonly) is a fallback to my Clipper coding from many years ago

In code review today, I noticed a reference to IsEmpty instead in a similar block of code. Is this just a preference or is there any real difference in the example scenario?

MyStoredProc.Open;
if not MyStoredProc.IsEmpty then
begin
  DoSomething;
end;

Where I usually use

MyStoredProc.Open;
if not MyStoredProc.Eof then
begin
  DoSomething;
end;

Mostly because it mirrors the practice of what I use in a while loop when it's more than one record:

MyStoredProc.Open;
while not MyStoredProc.Eof then
begin
  DoSomething;
  MyStoredProc.Next;
end;
like image 535
Darian Miller Avatar asked Oct 16 '25 12:10

Darian Miller


2 Answers

The IsEmpty property is for check if the dataset has records, and Eof is for check if the current record is the last. In your case if you need iterate over a dataset use eof to determine if you reach the last record.

like image 117
RRUZ Avatar answered Oct 19 '25 10:10

RRUZ


IsEmpty is equivalent to Bof and Eof, not equivalent to Eof.

In this particular case, directly after opening a new dataset it is equivalent to Eof (because you know Bof also holds), but in general it is not.

like image 23
Jeroen Wiert Pluimers Avatar answered Oct 19 '25 09:10

Jeroen Wiert Pluimers