RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TTable.FindKey Method

Searches for a record containing specified field values.

Pascal
function FindKey(const KeyValues: array of const): Boolean;
C++
__fastcall Boolean FindKey(const array of const KeyValues);

Call FindKey to search for a specific record in a dataset. KeyValues contains a comma-delimited array of field values, called a key. Each value in the key can be a literal, a variable, nil (Delphi) or NULL (C++). If the number of values passed in KeyValues is less than the number of columns in the index used for the search, the missing values are assumed to be null. KeyValues_Size specifies the index of the last value in KeyValues (one less than the total number of values supplied). In the statement below, the FindKey method is used to find the table row with the value "'Princess Island SCUBA" in the index field.

Table1.FindKey(['Princess Island SCUBA']);

 

TVarRec vr = ("Princess Island SCUBA");
Table1->FindKey(&vr, 0);

Note: In C++ code, the search values can be passed to FindKey using either a TVarRec (as above) or an ARRAYOFCONST construct. The example below performs the same search as the preceding example, but using ARRAYOFCONST.

Table1->FindKey(ARRAYOFCONST(("Princess Island SCUBA")));

For Paradox and dBASE tables, the key must always be an index, which can be specified in the IndexName property. If IndexName is empty, FindKey uses the table's primary index. Note that FindKey does not work with dBASE expression indexes. Use the GotoKey or GotoNearest method instead. 

For SQL tables, the key may correspond to a specified index in IndexName, or to a list of field names in the IndexFieldNames property. 

If the search is successful, FindKey positions the cursor on the matching record and returns true. Otherwise the cursor is not moved, and FindKey returns false. 

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!