性能上是否有任何差异或其他差异,或者两者是相同的(根据 TADOquery 和 TCustomADODataSet 中的查找字段)?
我已阅读帮助文件,但没有找到任何对此进行解释的内容。
最佳答案
Lookup()
函数是TDataSet
的虚函数。
作为虚函数意味着实现可以根据类的不同而改变。
因此,文档具有不同的注释,这些注释因每个 TDataSet
后代而异。
让我们仔细看看:
TDataSet
的Lookup()
:
Implements a virtual method to retrieve field values from a record that matches specified search values.
查看更多here
请注意文档末尾的此注释:
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
的Lookup()
:
这里,上面的言论是在实践中发生的。请注意,在此实现中,没有调用 inherited。
文档说:
Retrieves field values from a row that matches specified search values.
详情here
现在,你只能通过深入源码来了解其中的区别。最后,您会发现根本没有区别。您将意识到查找字段只会调用 Lookup()
函数:
1.查找字段就像计算字段。
- 受
AutoCalcFields
属性影响(请参阅 here) - 与触发
OnCalcFields
事件负责的功能相同 调用CalcLookupValue
UniDirectional
DataSet 也没有Lookup
字段。 (看 here )
2. Lookup
字段调用 Lookup()
函数
- 对此,没有文档,您必须自己查看:
过程 TField.CalcLookupValue;
Lookup()
参数由TField
属性填充:FLookupDataSet.Lookup(FLookupKeyFields, FDataSet.FieldValues[FKeyFields], FLookupResultField);
Lookup()
函数使用查找字段中的所有相关属性,如上所示:
- FKeyFields = TField.KeyFields
- FLookupDataSet = TField.LookupDataSet
- FLookupKeyFields = TField.LookupKeyFields
- FLookupResultField = TField.LookupResultField
关于delphi - 字段查找和函数查找有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23518471/