[Lazarus] SendMessage problem?

Anthony Walter sysrpl at gmail.com
Mon Oct 1 13:51:56 CEST 2012


I am using Linux Gtk2 here ...

Is there a problem with SendMessage? I am using LCLIntf.SendMessage to
synchronize a method invocation which touches the ui from a background
thread. The problem is when my message is handled, the message handler
isn't in the correct thread context. That is 'procedure LMRender(var
Msg: TLMessage); message LM_RENDER;' is not invoked in the ui thread.
Why?

According to http://wiki.freepascal.org/Multithreaded_Application_Tutorial#Using_SendMessage.2FPostMessage_to_communicate_between_threads

Only one thread in an application should call LCL APIs, usually the
main thread. Other threads can make use of the LCL through a number of
indirect methods, one good option being the usage of SendMessage

And at http://lazarus-ccr.sourceforge.net/docs/lcl/lclintf/postmessage.html

This method is a thread-safe solution to send messages to windows.
Those messages will be handled in the message loop of the application
and therefore can be sent from any thread.

"the message loop of the application" should be the same thread
context as the ui thread.




More information about the Lazarus mailing list