RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDataSet.Eof Property

Indicates whether a dataset is positioned at the last record.

Pascal
property Eof: Boolean;
C++
__property Boolean Eof;

Test Eof (end-of-file) to determine if the active record in a dataset is the last record. If Eof is true, the current record is unequivocally the last row in the dataset. Eof is true when an application: 

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. 

Eof is false in all other cases.

Tip: If both Eof and Bof are true, the dataset or range is empty.
 

Delphi Examples: 

 

{
Usually DisableControls is called within the context of a
try...finally block that reenables the controls even if an
exception occurs. For example:
} 
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  ListBox1.Clear;
  ListBox1.Items[0]:= 'Destination Airports:';
  with Flights do
  begin
    DisableControls;
    try
      First;
      i:= 1;
      ListBox1.Items[0]:= 'Destination Airports:';
      while not Eof do
      begin
        ListBox1.Items[i]:= Fields[2].Value;;
        i:= i + 1;
        Next;
      end;
    finally
      EnableControls;
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  Flights:= TTable.Create(Form1);
  with Flights do
  begin
    TableName := 'Flights';
    // This path depends on the Demos directory of your RAD Studio installation.
    DatabaseName :=
      'c:\Documents and Settings\All Users\Documents\RAD Studio\6.0\Demos\IntraWeb\Win32\FlightInformation\Data';

  end;
  DS2.DataSet:= Flights;
  DBGrid2.DataSource.DataSet:= Flights;
  Flights.Active:= True;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!