How to send a message to a TThread from main thread in Delphi?

前端 未结 3 1343
余生分开走
余生分开走 2021-02-04 16:17

I want to send a message to a thread and handle it in the thread. How can I do this in Delphi? I guess PostMessage is the way to go, but the examples I\'ve seen so

3条回答
  •  礼貌的吻别
    2021-02-04 17:03

    Why would you need to do it? It is only for one reason that I ever had to create a message loop in a secondary thread, and that is because the thread used COM objects. The calls to OleInitialize() and OleUnitialize() are a sign that you need a standard GetMessage() loop. In that case it's also necessary to just post messages to that thread, using PostThreadMessage(), because normal blocking synchronization calls would interfere with the message loop. Otherwise, just don't do it.

    If you are at Delphi 2007 or 2009, be sure to look into OmniThreadLibrary by Primož Gabrijelčič, it should make your job much easier.

提交回复
热议问题