TMedDataset.Lookup TMedDataset

function Lookup(const KeyFields: string; const KeyValues: Variant; const ResultFields: string): Variant;

Description

Use Lookup to find a record meeting your criteria and return values from that record without moving the record pointer of the dataset. This can be especially useful when doing data validation on a record’s data while the record is still in edit or insert mode.

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.

ResultFields is a string which contains the names of the fields from which to return values. If values are to be returned from more than one field, ResultFields should be a list of field names delimited with semicolons.

Lookup returns a variant array containing the values from the fields specified in ResultFields.

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;

v: Variant;

pid: String;

begin

// . . .

v := products.Lookup('ProdClass;ProdID',VarArrayOf(['FOTO', 'F']), 'ProdID');

if not (VarType(v) in [varNull]) then

begin

pid := v[0];

writeln('ProdID=',pid);

end

else

writeln('Not found!');

end;