Asynchronous Calls

From Lazarus wiki
Revision as of 00:18, 13 December 2005 by Vincent (talk | contribs) (Solution: added links to docs)

Problem statement

When handling some event, you need to do something, but you can't do it right away. Example: you need to free an object, but it is or will be referenced somewhere in the parent (or its parent etc.) later on.

Solution

Call Application.QueueAsyncCall:

TDataEvent = procedure (Data: PtrInt) of object;

procedure QueueAsyncCall(AMethod: TDataEvent; Data: PtrInt);

This will "queue" the given method with the given parameter for execution in the main event loop, when all other events have been processed. In the example above, the reference to the object you wanted to free has gone, since the then-parent has finished execution, and the object you wanted to free can be freed safely.

Note that this is a more generic version of ReleaseComponent, and ReleaseComponent calls this method.