Navigating Datasets

From RAD Studio
Jump to: navigation, search

Go Up to Understanding Datasets Index


Each active dataset 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 Vcl.DBCtrls.TDBEdit, TDBLabel, and Vcl.DBCtrls.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:

Navigational methods of datasets:

Method Moves the Cursor to

First

The first row in a dataset.

Last

The last row in a dataset. (not available for unidirectional datasets)

Next

The next row in a dataset.

Prior

The previous row in a dataset. (not available for unidirectional datasets)

MoveBy

A specified number of rows forward or back in a dataset.


The data-aware, visual component Vcl.DBCtrls.TDBNavigator encapsulates these methods as buttons that users can click to move among records at run time. For information about the navigator component, see Navigating and Manipulating Records.

Whenever you change the current record using one of these methods (or by other methods that navigate based on a search criterion), the dataset receives two events: Data.DB.TDataSet.BeforeScroll (before leaving the current record) and Data.DB.TDataSet.AfterScroll (after arriving at the new record). You can use these events to update your user interface (for example, to update a status bar that indicates information about the current record).

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

Navigational properties of datasets:

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.


The following topics discuss these properties and methods in more detail:

See Also