如何使用Delphi 5在大型TIBQuery数据集上执行快速搜索?

时间:2019-06-12 11:24:44

标签: performance delphi dataset delphi-5 locate

我正在处理一个使用TIBQuery数据集的古老的Delphi 5项目。

我需要关闭数据集,删除它的主数据源,再次打开数据集,并激活最初集中的同一条记录。

该数据集包含35个字段和15.000条记录,调用Locate函数时,我的性能下降了(大约需要1分钟35秒)。

var
  PrevId : Variant;
begin
  //save the id
  PrevId := DstID.AsVariant;
  //close data
  Dst.Close();
  //remove the master dataset
  Dst.DataSource := nil;
  //load data
  Dst.Open();
  //go to the saved id
  Dst.Locate(DstID.FieldName, PrevId, []);
end;

我知道主要的慢速原因是大量的记录,但这不是我可以控制的一个方面。

我尝试使用DisableControls / EnableControls,但对性能没有太大影响(比以前少5秒)。

var
  PrevId : Variant;
begin
  Dst.DisableControls();
  try
     //save the id
     PrevId := DstID.AsVariant;
     //close data
     Dst.Close();
     //remove the master dataset
     Dst.DataSource := nil;
     //load data
     Dst.Open();
     //go to the saved id
     Dst.Locate(DstID.FieldName, PrevId, []);
  finally
     Dst.EnableControls();
  end;
end;

还有其他一些优化可以提高大型数据集的Locate的速度吗?

0 个答案:

没有答案