AnyDAC supports different execution modes. To check the current operation status use ADQuery1.Command.State
. This is pseudo-code (I don't have Delphi here):
ADQuery1.ResourceOptions.CmdExecMode := amAsync;
ADQuery1.Open;
while ADQuery1.Command.State = csExecuting do
begin
// This is NOT RECOMMENDED
Application.ProcessMessages;
Sleep(1);
end;
However, since the only thing you are doing in your while
block is processing GUI messages, I think your best bet is using amNonBlocking
mode, which will wait for the query to finish (thus avoiding the while
block) but doesn't block the GUI (it does ignore keyboard and mouse events, thought.)
ADQuery1.ResourceOptions.CmdExecMode := amNonBlocking;
ADQuery1.Open;
For more information, see the documentation in the developer's website: Asynchronous Execution.