Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)?

like image 883
ae1080 Avatar asked Apr 22 '26 21:04

ae1080


1 Answers

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.

like image 114
oodesigner Avatar answered Apr 26 '26 06:04

oodesigner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!