Icon Navigating Tables and Query Result Sets

Introduction
Navigation of tables and query result sets is accomplished through several methods of the TDBISAMTable and TDBISAMQuery components. The basic navigational methods include the First, Next, Prior, Last, and MoveBy methods. The Bof and Eof properties indicate whether the record pointer is at the beginning or at the end of the table or query result set, respectively. These methods and properties are used together to navigate a table or query result set.

Moving to the First or Last Record
The First method moves to the first record in the table or query result set based upon the current index order. The Last method moves to the last record in the table or query result set based upon the current index order. The following example shows how to move to the first and last records in a table:

begin
   with MyTable do
      begin
      First;
      {  do something to the first record }
      Last;
      { do something to the last record }
      end;
end;

Skipping Records
The Next method moves to the next record in the table or query result set based upon the current index order. If the current record pointer is at the last record in the table or query result set, then calling the Next method will set the Eof property to True and the record pointer will stay on the last record. The Prior method moves to the previous record in the table or query result set based upon the current index order. If the current record pointer is at the first record in the table or query result set, then calling the Prior method will set the Bof property to True and the record pointer will stay on the first record. The following example shows how to use the First and Next methods along with the Eof property to loop through an entire table:

begin
   with MyTable do
      begin
      First;
      while not Eof do
         Next;
      end;
end;

The following example shows how to use the Last and Prior methods along with the Bof property to loop backwards through an entire table:

begin
   with MyTable do
      begin
      Last;
      while not Bof do
         Prior;
      end;
end;

Skipping Multiple Records
The MoveBy method accepts a positive or negative integer that represents the number of records to move by within the table or query result set. A positive integer indicates that the movement will be forward while a negative integer indicates that the movement will be backward. The return value of the MoveBy method is the number of records actually visited during the execution of the MoveBy method. If the record pointer hits the beginning of file or hits the end of file then the return value of the MoveBy method will be less than the desired number of records. The following example shows how to use the MoveBy method to loop through an entire table 10 records at a time:

begin
   with MyTable do
      begin
      First;
      while not Eof do
         MoveBy(10);
      end;
end;
Image