查询数据库中的表建个进度条 | >> Dev-Club开始提供RSS订阅 |
![](http://www.dev-club.com/club/bbs/images/emote/mood25.gif)
![按此给该网友发送邮件](http://www.dev-club.com/club/bbs/images/email.gif)
![按此察看该网友的资料](http://www.dev-club.com/club/bbs/images/profile.gif)
![按此把文章加入书签](http://www.dev-club.com/club/bbs/images/fav.gif)
![按此给作者留言](http://www.dev-club.com/club/bbs/images/guestbook.gif)
![按此给作者发送即时消息](http://www.dev-club.com/club/bbs/images/chat.gif)
![按此查看作者个人专辑](http://www.dev-club.com/club/bbs/images/column.gif)
![按此打印本帖](http://www.dev-club.com/club/bbs/images/print.gif)
![按此打包转发本帖](http://www.dev-club.com/club/bbs/images/send.gif)
这段代码不是我自己写的,呵呵,是李维书上的.
直接编译附件里的工程就可以看到效果了.
unit fDemoMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, Grids, DBGrids, ExtCtrls, DBCtrls, Db, ADODB, StdCtrls;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADODataSet1: TADODataSet;
DataSource1: TDataSource;
DBNavigator1: TDBNavigator;
DBGrid1: TDBGrid;
ADOCommand1: TADOCommand;
ProgressBar1: TProgressBar;
Button1: TButton;
Button2: TButton;
procedure FormActivate(Sender: TObject);
procedure ADODataSet1FetchProgress(DataSet: TCustomADODataSet;
Progress, MaxProgress: Integer; var EventStatus: TEventStatus);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ADODataSet1FetchComplete(DataSet: TCustomADODataSet;
const Error: Error; var EventStatus: TEventStatus);
private
{ Private declarations }
lStart : Longint;
lEnd : Longint;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormActivate(Sender: TObject);
var
sRecNo : String;
begin
ProgressBar1.Max := ADOCommand1.Execute.Fields.Item[0].Value;
sRecNo := IntToStr(ProgressBar1.Max);
Self.Caption := '共有' + sRecNo + ' 笔资料';
end;
procedure TForm1.ADODataSet1FetchProgress(DataSet: TCustomADODataSet;
Progress, MaxProgress: Integer; var EventStatus: TEventStatus);
begin
ProgressBar1.Position := Progress;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
try
ADODataSet1.Active := False;
ADODataSet1.ExecuteOptions := [eoAsyncFetchNonBlocking];
finally
lStart := GetTickCount;
ADODataSet1.Active := True;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
try
ADODataSet1.Active := False;
ADODataSet1.ExecuteOptions := [eoAsyncFetch];
finally
lStart := GetTickCount;
ADODataSet1.Active := True;
end;
end;
procedure TForm1.ADODataSet1FetchComplete(DataSet: TCustomADODataSet;
const Error: Error; var EventStatus: TEventStatus);
begin
lEnd := GetTickCount;
ShowMessage('总共花了' + FloatToStr((lEnd - lStart) / 1000.0) + '秒');
end;
end.