On the Application object you have
procedure QueueAsyncCall(const AMethod: TDataEvent; Data: PtrInt);
procedure RemoveAsyncCalls(const AnObject: TObject);
You can add your new method to TForm.
type TForm1 = class(TForm)
...
procedure MyErrMethod(Data: PtrInt)
And then
Application.QueueAsyncCall(@MyErrMethod);
You can store a flag somewhere, and check the flag in "MyErrMethod".
You can remove the method
Application.RemoveAsyncCalls(self); // when self=form1
As you see, if form1 would have other asyncs queued, then they would also be removed.
Also note: In Form1.Destroy you should call the RemoveAsyncCalls. Otherwise your method could be called with a destroyed Form1 in self. OUch.
You can queue multiple times, leading to multiple invocations. To avoid that, you can keep a flag if you already queued.
Then you end up with
type TForm1(TForm)
private
FHasQueuedErrMethod: Boolean;
FHasError: Boolean;
procedure SetHasError;
procedure ClearHasError;
The procedures "SetHasError" queues an Async, but only if none is pending.
ClearHasError will remove the async method.