简体   繁体   English

TDataset的Lookup和Locate方法有多长时间了?

[英]How long have the Lookup and Locate methods of TDataset been around?

I'm working on modernizing and fixing bugs in the codebase of a Delphi 4-era program written by someone else. 我正在努力在其他人编写的Delphi 4时代程序的代码库中进行现代化和修复错误。 A lot of the code is kinda scary by modern standards, and I can't help but wonder if some of the things I'm seeing are there because the original author didn't know about certain standard library features, or if they weren't available. 很多代码在现代标准下都有点可怕,我不禁想知道我看到的一些东西是否存在,因为原作者不知道某些标准库的功能,或者它们是不是可用。

One of the more obnoxious "patterns" I see all over the app looks like this: 我在应用程序中看到的一个更令人讨厌的“模式”看起来像这样:

table := TClientDataset.Create;
with table do
begin
  CloneCursor(dmDatabase.OriginalTable, false, true);
  filtered := true;
  active := true;
  first;
  while not EOF do
  begin
    if fieldByName('whatever').AsString = 'some criteria' then break;
    next;
  end;
  if EOF then exit;
  //do something based on the current row of the dataset
  table.free;
end;

Almost every one of these groups could be replaced by a one-line call to either Lookup or Locate on the original dataset, with no need for an intermediary CDS at all. 几乎所有这些组都可以替换为原始数据集上的LookupLocate的单行调用,而根本不需要中间CDS。 That makes me wonder, were these methods available back in the D4 days? 这让我想知道,这些方法是否在D4时代可用? When were Lookup and Locate first added? 什么时候LookupLocate首先添加?

在Delphi 2中引入了Lookup和Locate。看起来原作者根本没有利用它们。

Seems the Original programmer wanted to make sure that the row pointer is not changed at all. 似乎原始程序员想要确保行指针根本没有改变。 Doing Locate (or Lookup ) would change the row pointer, provoking all kinds of data events (Datasource.OnDataChange, Dataset.AfterScroll and so on). 执行Locate (或Lookup )将更改行指针,激发各种数据事件(Datasource.OnDataChange,Dataset.AfterScroll等)。

Doing the search with TClientDataset.CloneCursor , none of the these events ger triggered on the dmDatabase.OriginalTable and there's no need to reload the data from database. 使用TClientDataset.CloneCursor进行搜索时, dmDatabase.OriginalTable上没有触发这些事件,也无需从数据库重新加载数据。

Seems to me that is the intention. 在我看来这是意图。 TClientDataset was presented on D3. TClientDataset在D3上展示。 And cloned cursors are a kind of advanced feature - and need the dmDatabase.OriginalTable to be a CDS too. 克隆游标是一种高级功能 - 需要dmDatabase.OriginalTable也是一个CDS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM