There are two procedures, A1 and A2, which both call function B in their code:
function B: boolean; begin // do other stuff end; procedure A1; begin // do stuff if b then ... // do stuff end; procedure A2; begin // do stuff if b then A1; // <- how to call A1 'delayed'? // do stuff end;
If the condition in A2 is true, procedure A1 must be called, but that would happen while A2 is still running, which I don’t want.
What should happen is: If the condition in A2 is true, then A2 should be finished and after leaving A2 the procedure A1 should be called.
An ugly solution would be to set a timer that calls A1 after a delay that makes sure A2 is finished.
But there must be better ways, right?
EDIT: A1 and A2 in my case are events, so they are not called by code and I cannot just call A1 from a calling procedure after A2 is finished.
Given your constraints it sounds like you want to call
PostMessageas the last thing inA2before returning. ThePostMessageparameters should be set up so trigger theA1event. The only thing to worry about it a race condition, but I’m not sure that’ll be an issue with the windows message queue.