TMedDataset.Locate TMedDataset

function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean;

Description

Use Locate to find a record meeting your criteria and position the cursor on it.

KeyFields specifies a semicolon-delimited list of field names which will be used for search.

KeyValues is a variant array which contains the values to match with the corresponding fields specified in KeyFields. If KeyFields contains more than one field, pass variant array as KeyValues parameter. If only one field is specified in KeyFields, pass only one variant value to match specified field value.

Method returns true if it finds a matching record, otherwise it returns false.

If record is found, it becomes the current one.

Using Options parameter you can specify additional search criteria for string fields. This set may contain two elements:

loPartialKey - last string field from the list will be matched partially - if its start characters are equal to the value specified, the field will be considered as matching criteria. The example below will find record which containf 'FOTO' in ProdClass field and any string begining with 'F' in ProdID field.

loCaseInsensitive - compare strings in case insensitive mode

For non-string fields the above options are ignored.

Locate attempts to use the fastest possible method for its search. It there is an index which index the specified fields and supports the supplied options it is used for search. Otherwise filter is created to perform the search.

Example:

var

products: TMedTable;

found : Boolean;

begin

// . . .

found := products.Locate('ProdClass;ProdID',VarArrayOf(['FOTO', 'F']), [loPartialKey]);

if found then . . .

end;