FireDAC.Comp.DataSet.TFDDataSet.LookupEx
Delphi
function LookupEx(const AKeyFields: string; const AKeyValues: Variant; const AResultFields: string; AOptions: TFDDataSetLocateOptions = []; ApRecordIndex: PInteger = nil): Variant; overload; virtual;
function LookupEx(const AExpression, AResultFields: string; AOptions: TFDDataSetLocateOptions = []; ApRecordIndex: PInteger = nil): Variant; overload; virtual;
C++
virtual System::Variant __fastcall LookupEx(const System::UnicodeString AKeyFields, const System::Variant &AKeyValues, const System::UnicodeString AResultFields, TFDDataSetLocateOptions AOptions = TFDDataSetLocateOptions() , System::PInteger ApRecordIndex = (System::PInteger)(0x0))/* overload */;
virtual System::Variant __fastcall LookupEx(const System::UnicodeString AExpression, const System::UnicodeString AResultFields, TFDDataSetLocateOptions AOptions = TFDDataSetLocateOptions() , System::PInteger ApRecordIndex = (System::PInteger)(0x0))/* overload */;
Contents
Properties
| Type | Visibility | Source | Unit | Parent |
|---|---|---|---|---|
| function | public | FireDAC.Comp.DataSet.pas FireDAC.Comp.DataSet.hpp |
FireDAC.Comp.DataSet | TFDDataSet |
Description
Searches the dataset for a set of specified key field values or a predicate expression for a record and returns the resulted field values.
This method is overloaded:
- Use the first LookupEx overloaded method to search a dataset for a record with the specified key field values.
AKeyFieldsis a semicolon-separated list of field names through which to search.AKeyValuesis a Variant containing the values to match to the key fields. IfAKeyFieldscontains a single field name, thenAKeyValuesis a simple value. IfAKeyFieldscontains more field names, thenAKeyValuesis a variant array, where items correspond to the key fields. - Use the second LookupEx overloaded method to search a dataset for a record in which the specified predicate expression evaluates to True.
AExpressionis a string containing the predicate expression through which to search. The expression cannot contain aggregating functions such asSUM,COUNTand it is evaluated to True or False. FireDAC supports extended expression syntax.
If a matching record is found,LookupEx returns a variant array containing the values from the fields specified in AResultFields. Otherwise, it returns null. The variable pointed by ApRecordIndex receives the index of the found record, if ApRecordIndex is not nil.
To optimize record searching, the application can set up the client index. The index will be used by the LookupEx if the following conditions are met:
- The index field list has as prefix
AKeyFieldsfields. - The index is build without the
soNoCaseoption. - The index is active and is the current one.
AOptions is a set that optionally specifies additional search modes:
|
Option |
Description |
|---|---|
|
|
If included, then LookupEx ignores case when matching string values. |
|
|
If included, then |
|
|
If included, then LookupEx starts searching from the next after current record in the dataset, otherwise from the beginning. |
|
|
If included, then LookupEx searches for the record in backward direction, otherwise in forward direction. |
|
|
If included, then LookupEx does not:
|
|
|
If included, then FetchAll is not called. Therefore, the search is performed in the already fetched records. |
Example
procedure TForm1.Button1Click(Sender: TObject);
var
V: Variant;
C: Integer;
A: String;
begin
V := FDQuery1.LookupEx('Company = ''Blue Sports'' and State = ''OR''', 'CustNo;Addr1', [lxoCaseInsensitive]);
if not VarIsNull(V) then begin
C := V[0];
A := V[1];
ShowMessage(IntToStr(C) + #13#10 + A);
end
else
ShowMessage('The record is not found !');
end;