Send string data from Thread to main form

前端 未结 3 1598
灰色年华
灰色年华 2020-12-29 14:03

In Dephi, I create a thread, like this, which will send message to main form from time to time

Procedure TMyThread.SendLog(I: Integer);
Var
  Log: array[0..2         


        
3条回答
  •  情书的邮戳
    2020-12-29 14:31

    Use SendMessage().

    PostMessage() will process your message asynchronously, it basically puts into the target message queue and Returns immediately. At the time where the handler code accesses the data sent in wparam/lparam, your caller has already freed the string.

    In contrast, SendMessage() bypasses the message queue and calls the window proc directly (synchronously). At the time when SendMessage() returns, it is safe to free the string.

提交回复
热议问题