Using Indexes to Search for Records

From RAD Studio
Jump to: navigation, search

Go Up to Using Table Type Datasets


You can search against any dataset using the Locate and Lookup methods of TDataSet. However, by explicitly using indexes, some table type datasets can improve over the searching performance provided by the Locate and Lookup methods.

ADO datasets all support the Seek method, which moves to a record based on a set of field values for fields in the current index. Seek lets you specify where to move the cursor relative to the first or last matching record.

TTable and all types of client dataset support similar indexed-based searches, but use a combination of related methods. The following table summarizes the six related methods provided by TTable and client datasets to support index-based searches:

Index-based search methods :

Method Purpose

EditKey

Preserves the current contents of the search key buffer and puts the dataset into dsSetKey state so your application can modify existing search criteria prior to executing a search.

FindKey

Combines the SetKey and GotoKey methods in a single method.

FindNearest

Combines the SetKey and GotoNearest methods in a single method.

GotoKey

Searches for the first record in a dataset that exactly matches the search criteria, and moves the cursor to that record if one is found.

GotoNearest

Searches on string-based fields for the closest match to a record based on partial key values, and moves the cursor to that record.

SetKey

Clears the search key buffer and puts the table into dsSetKey state so your application can specify new search criteria prior to executing a search.



GotoKey and FindKey are boolean functions that, if successful, move the cursor to a matching record and return True. If the search is unsuccessful, the cursor is not moved, and these functions return False.

GotoNearest and FindNearest always reposition the cursor either on the first exact match found or, if no match is found, on the first record that is greater than the specified search criteria.

The following topics discuss the Goto and Find methods in greater detail:

See Also