Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-10

SendMessage problem?

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Anthony Walter

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.

Reply by email