From RAD Studio API Documentation
Jump to: navigation, search


function Lookup(const AKeyFields: string; const AKeyValues: Variant;  const AResultFields: string): Variant; override;


virtual System::Variant __fastcall Lookup(const System::UnicodeString AKeyFields, const System::Variant &AKeyValues, const System::UnicodeString AResultFields);


Type Visibility Source Unit Parent
function public
FireDAC.Comp.DataSet TFDDataSet


Searches the dataset for a record with the specified key field values and returns the resulted field values.

Use Lookup to search the dataset for a record with the specified key field values and return the resulted field values without changing the current position in the dataset. 

AKeyFields is a list of field names separated by semicolons on which to perform the search.  AKeyValues is a Variant containing the values to match to the key fields. If AKeyFields contains a single field name, then AKeyValues is a simple value. If AKeyFields contains several field names, then AKeyValues is a variant array where items correspond to the key fields.   AResultFields is a semicolon-separated list of field names whose values are returned. If the record is found, Lookup returns a variant array containing the values from the fields specified in AResultFields. Otherwise, it returns nil

To optimize record searching, an application can set up a client index. The index will be used by the Lookup if following conditions are met:

  • The index field list has as prefix AKeyFields fields.
  • The index is build without the soNoCase option.
  • The index is active and is current.


procedure TForm1.Button1Click(Sender: TObject);
  V: Variant;
  C: Integer;
  A: String;
  V := FDQuery1.Lookup('Company;State', VarArrayOf(['Blue Sports', 'OR']), 'CustNo;Addr1');
  if not VarIsNull(V) then begin
    C := V[0];
    A := V[1];
    ShowMessage(IntToStr(C) + #13#10 + A);
    ShowMessage('The record is not found !');

See Also