EPUB | CHM | PDF

TMySQLTable.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 MySQL tables, the key may correspond to a specified index in TMySQLTable.IndexName, or to a list of field names in the TMySQLTable.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 and master-detail tables will not work properly too because of their dependence on Locate method. Please update your IDE to BDS 2006 (or later) or don't use BIGINT and UNSIGNED INT datatypes for keys and indexes if you need to use them in lookup fields. Also you can't use variant-style properties (FieldValuesAsVariant and so on) with such fields.

See also: Example: FindNearest