Question

Is there any difference in performance or another difference or are both the same thing (as per the lookup fields in the TADOquery and TCustomADODataSet)?

I have read the Help files, but I didn't found anything explaining on this.

Was it helpful?

Solution

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's Lookup():

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's Lookup():

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 calling CalcLookupValue
  • UniDirectional DataSet also do not have Lookup 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 the TField 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top