如何在执行DBExpress查询时保持程序对用户输入的响应?

时间:2011-09-19 09:33:17

标签: delphi dbexpress

ibdac查询(http://www.devart.com/ibdac/components.html)有一个函数executing,我可以在其中编写如下内容:

 while MyQuery.Executing do
 begin
   application.ProcessMessages;
   Sleep(1);
 end;

如何使用dbexpress查询实现相同的代码(没有类似的功能)?

1 个答案:

答案 0 :(得分:5)

没有类似的功能。但是你可以在后台线程中执行MyQuery,主线程将在后台线程完成时等待。例如:

type
  TMyThread = class(TThread)
  private
    FQuery: TSQLQuery;
  protected
    procedure Execute; override;
  public
    constructor Create(AQuery: TSQLQuery);
  end;

constructor TMyThread.Create(AQuery: TSQLQuery);
begin
  inherited Create;
  FreeOnTerminate := False;
  FQuery := AQuery;
end;

procedure TMyThread.Execute;
begin
  FQuery.ExecSQL;
end;

var
  oThread: TMyThread;
....

  oThread := TMyThread.Create(MyQuery);
  try
    while not oThread.Finished do begin
      Application.ProcessMessages;
      Sleep(1);
    end;
  finally
    oThread.Free;
  end;

PS:顺便说一下,我正在使用AnyDAC。它内置了background execution