Using EnterCriticalSection in Thread to update VCL label

Posted by user257188 on Stack Overflow See other posts from Stack Overflow or by user257188
Published on 2010-03-15T17:39:15Z Indexed on 2010/03/15 17:39 UTC
Read the original article Hit count: 380

Filed under:
|

I'm new to threads. I'm using a 3rd party library that uses threads which at times call a procedure I've provided.

How do I update update a TLabel.Caption from my procedure when its called by the thread?

If I've called InitializeCriticalSection elsewhere, is it as simple as

  EnterCriticalSection(CritSect);
  GlobalVariable := 'New TLabel.Caption';
  LeaveCriticalSection(CritSect);

And then in my main thread:

  EnterCriticalSection(CritSect);
    Label1.Caption:= 'New TLable.Caption';
  LeaveCriticalSection(CritSect);

But, how do I get the main thread code to be called? The thread can use SendMessage? Or is there some better/easier way (.OnIdle could check a flag set by the thread?)

Thanks.

© Stack Overflow or respective owner

Related posts about delphi

Related posts about thread-safety