Delphi Database, Delphi Components from ComponentAce
Products Download Order Contact us
Navigating Tables and Queries
Previous  Top  Next



Each active dataset (table or query) has a cursor, or pointer, to the current row in the dataset. The current row in a dataset is the one whose field values currently show in single-field, data-aware controls on a form, such as TDBEdit, TDBLabel, and TDBMemo. If the dataset supports editing, the current record contains the values that can be manipulated by edit, insert, and delete methods.

You can change the current row by moving the cursor to point at a different row. The following table lists methods you can use in application code to move to different records:

Method
Moves the cursor to
First
The first row in a dataset.
Last
The last row in a dataset.
Next
The next row in a dataset.
Prior
The previous row in a dataset.
MoveBy
A specified number of rows forward or back in a dataset.

   
TDataSet also defines three properties that provide useful information when iterating through the records in a dataset.

Property
Description
Bof (Beginning-of-file)
True: the cursor is at the first row in the dataset.False: the cursor is not known to be at the first row in the dataset
Eof (End-of-file)
True: the cursor is at the last row in the dataset.False: the cursor is not known to be at the first row in the dataset
RecNo
Indicates the active record in the dataset.


The following code illustrates one way you might code a record-processing loop for a table called ABSTable1:

Example:

AbsTable1.DisableControls;

try
  AbsTable1.First; { Go to first record, which sets Eof False }

  while not AbsTable1.Eof do { Cycle until Eof is True }

  begin
    { Process each record here }

    ...
    AbsTable1.Next; { Eof False on success; Eof True when Next fails on last record }

  end;
finally
  AbsTable1.EnableControls;
end;

Tip:   
This example also shows how to disable and enable data-aware visual controls tied to a dataset. If you disable visual controls during dataset iteration, it speeds processing because your application does not need to update the contents of the controls as the current record changes. After iteration is complete, controls should be enabled again to update them with values for the new current row. Note that enabling of the visual controls takes place in the finally clause of a try...finally statement. This guarantees that even if an exception terminates loop processing prematurely, controls are not left disabled.
   
   
   

        © 2003 - 2024 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Dec 04, 2024