delphi - 字段查找和函数查找有什么区别?

标签 delphi ado

性能上是否有任何差异或其他差异,或者两者是相同的(根据 TADOquery 和 TCustomADODataSet 中的查找字段)?

我已阅读帮助文件,但没有找到任何对此进行解释的内容。

最佳答案

Lookup()函数是TDataSet的虚函数。

作为虚函数意味着实现可以根据类的不同而改变。

因此,文档具有不同的注释,这些注释因每个 TDataSet 后代而异。

让我们仔细看看:

  • TDataSetLookup():

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.


  • TCustomADODataSetLookup():

这里,上面的言论是在实践中发生的。请注意,在此实现中,没有调用 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/

相关文章:

c++ - Delphi/C++ Builder - 在 TDBGrid 中设置事件/选定行颜色

forms - 在主窗体之前创建辅助窗体,同时保持 FormMain 作为主窗体?

sql - SQL 中的参数 - Delphi 7

c# - 如何给SqlCommand 添加参数?

excel - 将数据从 DBGrid 导出到 Excel

multithreading - Delphi:如何创建线程安全的全局TList?

delphi - 如何判断图形或图片是否损坏?

Delphi 2010 宽函数与字符串函数

Asp.Net 在 Sql 中选择

azure - 如何将参数从 Azure DevOps 管道传递到 Bicep 模板