On 11/03/2015 12:41 PM, Mark Morgan Lloyd wrote:

Thanks for that, useful. That's going to impact anybody trying to convert code that uses custom Windows messages to pass events around.

For Delphi users, it is a common (bad) habit to use PostMessage() for Thread to MainThread signaling. It was necessary pre D7. But as of D7, for this purpose there is TThread.Queue() (which only was documented only as of a later version of Delphi). Unfortunately only the SVN version of the FPC RTL provides TThread.Queue() (implemented some time ago on my request THANKS !!! ), But no officially released version has it yet.

A long time ago, I did a testing program that with an arbitrary Widget Type checks the "compileability" and the workability of
 - TThread.Synchronize
 - TThread.Queue
 - PostMessage
 - PostThreadMessage (AFAIK not implemented in Lazarus Linux)
 - SendMessage ()Forbidden to be called in a Thread)
 - Application.QueuAsycCall
 - Application.QueuAsycCall with additional parameter

I separated the business Logic and GUI to prepare it to test the "ActiveNoGui" (to be renamed to "GeneralServiceApplication") Widget Type, I intend to do and provide to be include into Lazarus. (In fact the draft of same does have most of this but still is lacking "PostMessage".

I don't think I've used QueueAsyncCall() in the context of a non-GUI program. Where I do find it useful is when converting an interactive non-GUI (i.e. console) program into a Lazarus GUI app: enqueue an async call in the main form's FormCreate() with the payload being e.g. a looping interactive command interpreter which calls Application.ProcessMessages when it's got nothing to do.
Yep. As the "Main Loop" of the "GeneralServiceApplication" Widget Type uses the timeout of CheckSynchronize to implement TTimer, it can't call RemoveAsyncCalls(). So I implemented TApplication.QueuAsyncCall() by means of TThread.Queue (using a transfer class with a a would-be "Finalizer" procedure).


-Michael

--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to