开发者

How do I keep my program responsive to user input while executing a DBExpress query?

开发者 https://www.devze.com 2023-04-05 15:36 出处:网络
ibdac query ( http://www.devart.com/ibdac/components.html ) has a function executing where I can write something like:

ibdac query ( http://www.devart.com/ibdac/components.html ) has a function executing where I can write something like:

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

how do I implement the same code with a dbexpress query (there is no similar开发者_开发问答 function)?


There is no similar functionality. But you can execute MyQuery in a background thread and main thread will wait when the background thread is finished. For example:

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: Btw, i am using AnyDAC. It has build-in background execution.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号