Bde.DBTables.TTable.FindKey

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function FindKey(const KeyValues: array of const): Boolean;

C++

bool __fastcall FindKey(const System::TVarRec *KeyValues, const int KeyValues_High);

Properties

Type Visibility Source Unit Parent
function public
Bde.DBTables.pas
Bde.DBTables.hpp
Bde.DBTables TTable

Description

Searches for a record containing specified field values.

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 primary index of the table. 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.

See Also