EPUB | CHM | PDF

TPSQLTable.Methods.FindNearest

Top Previous Next

Moves the cursor to the record that most closely matches a specified set of key values.

Syntax:

procedure FindNearest(
  const KeyValues: array of const);

Description:

Call FindNearest to move the cursor to a specific record in a dataset or to the first record in the dataset that is greater than the values specified in the KeyValues parameter. KeyValues contains a comma-delimited array of field values, called a key. Each value in the key can be a literal, a variable, a null, or nil. 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.

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

FindNearest positions the cursor either on a record that exactly matches the search criteria, or on the first record whose values are greater than those specified in the search criteria. KeyExclusive affects the boundary conditions of ranges and will affect the record selected by FindNearest.

Delphi 7 and prior has poor support for int64 values in variant type. This means that you'll be unable to use Locate() and similar methods with such fields. Lookup fields will not work proper too due to their dependence on Locate() method. Please update your IDE to BDS 2006 or don't use bigint (int8) and bigserial datatypes for keys and indexes if you need to use them in lookup fields.

See also: Example: FindNearest