1
votes

I'm using Delphi XE2 with Firedac components. I have quite strange problem. I have custom component, which uses own Firedac TQuery component to search some data. Strange thing is, that after opening the query - it is not active yet.

qry.Open;
ShowMessage(BoolToString(qry.Active,True);
FunctionToDoAfter(SilentMode);

With that part of the code I have 'False' in the message. It seams that the TQuery.Open method runs some thread to open it. Can someone pls advise me, how can I wait for open the query, before I run the FunctionToDoAfter?

best regards, Piotr

1
Do you have a TADGUIxWaitCursor on your form, and if not, have you tried adding one?MartynA
Did you change the value of the ResourceOptions.CmdExecMode property (I guess you've just switched to an asynchronous mode) ?TLama
MartynA - I have *WaitCursor component on the application. Not in the CustomComponent, but i didn't try to add some.Quasik

1 Answers

2
votes

TLama - that was the 10 point shot, thanks. I've added the amAsync mode some months ago, and I think I didn't realase the all functionality then.

Now I read one more time the help site here, and there is exact answer on my question in the example with 'while' loop.

I'm new on stackoverlflow, how can I repay you, TLama? You saved few my hours :)

Edit 1

Following Frazz sugestion, i'll try to copy some information from the source page linked above.

FireDacs have four modes for commands execute. You can change it in FDQuery1.ResourceOptions.CmdExecMode. You can also set the timeout for executing command in FdQuery1.ResourceOptions.CmdExecTimeout.

The CmdExecModes are:

amBlocking -- The calling thread and GUI are blocked until an action is finished.

amNonBlocking -- The calling thread is blocked until an action is finished. The GUI is not blocked.

amCancelDialog -- The calling thread and GUI are blocked until an action is finished. FireDAC shows a dialog, allowing to cancel an action.

amAsync -- The calling thread and GUI are not blocked. The called method returns immediately.

You can wait while the command is executing, by checking the command state:

FDQuery1.ResourceOptions.CmdExecMode := amAsync;
FDQuery1.Open;
  while FDQuery1.Command.State = csExecuting do begin
  // do something while query is executing
end;

There is 6 different command states: csInactive, csPrepared, csExecuting, csOpen, csFetching, csAborting.