The Lookup()
function is a virtual function of TDataSet
.
Being a virtual function means that the implementation can change from class to class.
Because of this, the documentation has different comments that varies from each TDataSet
descendant.
Let's take a closer look:
TDataSet
'sLookup()
:
Implements a virtual method to retrieve field values from a record that matches specified search values.
See more here
Note this remark at the end of the document:
Descendant classes that are not unidirectional override this method so that it locates the record where the fields identified by the comma-delimited string KeyFields have the values specified by the Variant or Variant array KeyValues. In classes that implement Lookup, it returns a Variant or Variant array that contains the value or values of the fields specified by the comma-delimited string ResultFields on the specified record.
TCustomADODataSet
'sLookup()
:
Here, the remark above is happening in pratice. Note, in this implementation there is no call to inherited.
The Documentation says:
Retrieves field values from a row that matches specified search values.
Details here
Now, you can only understand the difference by digging into the source code. At the end, you will note that there is no difference at all. You will realise that the lookup fields will just call Lookup()
function:
1. A lookup field is like a calculated field.
- Is affected by the
AutoCalcFields
property (See here) - The same function the fires
OnCalcFields
event is responsible for callingCalcLookupValue
UniDirectional
DataSet also do not haveLookup
Fields. (See here)
2. The Lookup
Field calls the Lookup()
Function
- On this, there is no documentation, you will have to see for yourself:
procedure TField.CalcLookupValue;
- The
Lookup()
arguments is filled with theTField
properties:FLookupDataSet.Lookup(FLookupKeyFields, FDataSet.FieldValues[FKeyFields], FLookupResultField);
The Lookup()
function consumes all related properties from the lookup field, as you can see above:
- FKeyFields = TField.KeyFields
- FLookupDataSet = TField.LookupDataSet
- FLookupKeyFields = TField.LookupKeyFields
- FLookupResultField = TField.LookupResultField