为什么ADO Next记录处理在Delphi中减慢? [英] Why does ADO Next record processing slow down in Delphi?

查看:327
本文介绍了为什么ADO Next记录处理在Delphi中减慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Delphi 4程序,我开发了很多年前,使用 Opus DirectAccess 顺序搜索Microsoft Access数据库并检索所需的记录。 Delphi 4没有ADO,所以我正在使用DirectAccess。



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

  ArticlesTable.First; 
而不是取消而不是ArticleTable.Eof做开始

(查看当前记录是否需要标准)
(如果是,则处理记录)

ArticlesTable.Next;
结束

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



那么为什么会放慢速度,如何重新编码呢,这样不会减慢?

解决方案

如果您没有在数据集上使用数据库感知控件,则应该在所有ADO数据集上调用DisableControls。



否则速度变慢。 p>

有关详细信息,请参阅本文。 / p>

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

 而不是ADOQuery1。 Recordset.EOF do 
begin
ADOQuery1.Recordset.Movenext;
结束


I had a Delphi 4 program that I developed many years ago that used Opus DirectAccess to sequentially search through a Microsoft Access database and retrieve desired records. Delphi 4 did not have ADO, so that's why I was using DirectAccess.

But I've now upgraded to Delphi 2009 and converted the program to use ADO. What I found was that the loop through the table (of some 100,000 records) starts off as fast as it did in DirectAccess, but then it starts slowing down and gets slower and slower as it goes through the table. The basic loop is:

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;

So basically, it is just processing the records sequentially using the .Next method.

So why is it slowing down, and how can I recode this so that it won't slow down?

解决方案

You should call DisableControls on all ADO datasets if you aren't using DB aware controls on the dataset.

Otherwise the speed sucks.

refer to this article for details.

Alternatively, use the internal ado recordset property

while Not ADOQuery1.Recordset.EOF do
begin
  ADOQuery1.Recordset.Movenext;
end;

这篇关于为什么ADO Next记录处理在Delphi中减慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆