为什么ADO Next记录处理在Delphi中变慢?

lke*_*ler 5 delphi performance ado

我有一个多年前开发的Delphi 4程序,它使用Opus DirectAccess顺序搜索Microsoft Access数据库并检索所需的记录.Delphi 4没有ADO,所以这就是我使用DirectAccess的原因.

但我现在升级到Delphi 2009并将程序转换为使用ADO.我发现通过表(大约100,000条记录)的循环开始时和DirectAccess一样快,但随后它开始变慢,并且当它通过表时变得越来越慢.基本循环是:

ArticlesTable.First;
while not Cancel and not ArticlesTable.Eof do begin

  ( See if the current record has criteria desired )
  ( If so, process the record )

  ArticlesTable.Next;
end;
Run Code Online (Sandbox Code Playgroud)

所以基本上,它只是使用.Next方法顺序处理记录.

那么为什么它会变慢,我怎么能重新编码它以免它变慢?

Ger*_*oll 10

如果未在数据集上使用DB感知控件,则应在所有ADO数据集上调用DisableControls.

否则速度很糟糕.

有关详细信息,请参阅此文章.

或者,使用内部ado记录集属性

while Not ADOQuery1.Recordset.EOF do
begin
  ADOQuery1.Recordset.Movenext;
end;
Run Code Online (Sandbox Code Playgroud)