查询数据库中的表建个进度条 | >> Dev-Club开始提供RSS订阅 |
jianguobu 于 2004-6-19 9:09:15 加贴在 DELPHI ←返回版面:
这段代码不是我自己写的,呵呵,是李维书上的.
直接编译附件里的工程就可以看到效果了.
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.