The VCL (and parts of the RTL) is not thread-safe, so you cannot move components around from a thread. You have several options:
- Use a
TTimer
component. You don't need a thread and the timer's event handler will be executed in the context of the main thread. The timer was designed exactly for things like that. - Synchronize all VCL related stuff in the thread.
TThread
provides a static methodSynchronize
that does exactly that. - Send messages from the thread to the form using
SendMessage
orPostMessage
and handle this message in the form.
You might also consider to use the TThread
wrapper class instead of using BeginThread
and EndThread
explicitly when working with threads.
Smasher
2010-03-24 14:12:51