[Lazarus] How to PostMessage to object?
dibo20 at wp.pl
Thu Jun 9 20:00:53 CEST 2011
Huh, 35 new messages in my topic :) . After reading all, maybe I summarize
why I need post message to non-windowed object/component and why I can't use
PostMessage and for what I need this (on a real example).
So, I wrote TMyHTTPClient which is some kind of layer for synapse http
client but it do all jobs in thread. Simply structure:
TMyHTTPClient = class;
TSynThread = class(TThread)
TMyHTTPClient = class
Now, TSynThread communicate with TMyHTTPClient sending progress and response
data from server. I used TThread.Synchronize() for this but I often had
deadlocks because TMyHTTPClient cares about terminate and free thread (it
waiting in destructor until thread terminate). I could not find way to omit
deadlocks in case when thread blocking in synchronize() to send progress
data and TMyHTTPClient waiting for this thread termination (ProcessMessages
and CheckForSynchronize doesn't solve this on linux). So I tried solve this
using PostMessage instead of Synchronize but PostMessage need window handle.
In simple project, main form should be solution here (as mediator
and TSynThread) but my project is quite big and I use this http client in
many places, in many modules, in many cases (most in non-visual) and in many
instances. So I need something simpler. Now you reminded me about
Application.QueueAsyncCall and this is point where we are :) . I think that
critical section latency in thread is not problem in this case. I try update
lazarus source and test your "thread safe" fix for QueueAsyncCall.
Maybe my case could be resolved in many different ways, but good
communication mechanism between threads, certainly will be useful in
other cases :)
Sorry for my bad english, I tried describe it in details.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Lazarus