2

With sdac I can let the program responsive for user input as :

while Query.Executing do
begin
  Application.ProcessMessages;
  Sleep(1);
end;

How do I implement the same code with anydac query (there is no similar function)?

I'm using delphi xe2 and anydac v6.

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
ae1080
  • 374
  • 2
  • 7
  • 14
  • 9
    You should not be using `ProcessMessages()` like this, whether you use sdac or anydac or anything else for that matter. You should move lengthy blocking operations, like database queries, to their own separate thread instead and don't block the main thread at all. – Remy Lebeau Dec 26 '12 at 20:34
  • 1
    A quick review of the documentation at da-soft doesn't show any way to do this, but you should really be asking their support department. (And your code is very bad regardless of what it's doing; the call to `sleep(1)` uses a high percentage of the CPU to do nothing but call `ProcessMessages` again and again, which makes *other* apps slower to respond, too.) – Ken White Dec 26 '12 at 23:56
  • @Fred: No, the code he posted works with Devart; he's trying to solve a problem with da-soft's Anydac. Read the question again, and check the links posted in the question. – Ken White Dec 28 '12 at 13:22

1 Answers1

4

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.

Leonardo Herrera
  • 8,388
  • 5
  • 36
  • 66