How to see progress of query execution during hand

2019-01-19 07:45发布

问题:

I used the following code in delphi for handle :

procedure TForm1.ADOQuery1FetchProgress(DataSet: TCustomADODataSet; Progress,

  MaxProgress: Integer; var EventStatus: TEventStatus);

begin

    Progressbar1.Visible:=true;

    Progressbar1.Max:=MaxProgress;

    Progressbar1.Ppsitian:=Progress;

    Progressbar1.Visible:=false;

end;

but.... I can't see any effect (this code doesn't execute)

I want to show progress of query execution during when the user clicked a button for ٍُSEARCH in database from begining to finish filter in progressbar.

the button onclick codes :

with ADOQuery1 do

begin

SQL.Clear;

SQL.Add('select * from tbl1 where id = '+Edit1.Text);

Open;

end;

but i don't any mutation in the progress bar , as though don't write any code in OnFetchProgress event.

Did i represented you?

回答1:

you must set property ExecuteOptions to eoAsyncFetch before to call the open procedure

check this sample

with ADOQuery1 do
begin
 SQL.Clear;
 SQL.Add('select * from tbl1 where id = '+Edit1.Text);
 ExecuteOptions:=[eoAsyncFetch];
 Open;
end;


procedure TForm1.ADOQuery1FetchProgress(DataSet: TCustomADODataSet; Progress,
  MaxProgress: Integer; var EventStatus: TEventStatus);
begin
  ProgressBar1.Max      :=MaxProgress;
  ProgressBar1.Position :=Progress;
  Application.ProcessMessages;
end;