When you use objects of class hierarchies such as TThread, their properties and methods are not guaranteed to be thread-safe. That is, directly accessing other form properties or executing methods, the memory used is not protected from other threads. Because of this, a main thread is to prestage access to the VCL and CLX objects, so that all Windows components receive the message sent by the thread when it is processed, that is, all the controls on the application will use the message loop synchronously, while implementing the thread synchronization needs to be used to synchronize. VCL implementation of synchronous method is called the thread class synchronize process, this process requires a parameterless procedure, so in this procedure can not pass the parameter value, but may be implemented through the members of the class. You only have to call synchronize in the execute of the class. If the VCL operation in the thread, after several consecutive executions, will report errors or inexplicable display error problems, such as font size changes, font thickness, disappear, etc., this problem can be fixed by the above method, the assignment operation let the form main thread to complete. The key is the definition of the Synchronize parameter. Defines a parameterless procedure through which to access members of other classes. Call synchronize in the class's overloaded execute. procedureTmythread.pushthebutton;beginbutton1.caption:='Test'; Button1.Click;End;procedureTmythread.execute;begin ... Synchronize (Pushthebutton); ...End; Using synchronize will ensure that your operations on the Button1 control are thread-safe, but if you do not use synchronize and execute directly in the thread's Execute method, there are a variety of issues that occur because the execution is not threaded. If you do not perform the Button1 click event, or if the Button1 caption display font is large or small. Not all classes in the application need to use the main thread, so when you know that the method of an object is thread-safe, you can omit the use of the Synchronize method, which improves performance because there is no need to wait for a VCL or CLX thread to enter the message loop:1The control is not thread-safe, so manipulating the control in an object requires a synchronous display using the Synchronize method;2Graphical objects are thread-safe and you do not need to use the primary VCL or CLX threads to access Tfont,tpen,tbrush,tbitmap,tmetafile (VCL), tdrawing (CLX), or Ticon, The canvas object can be used to lock out the external synchronization method;3The list object is not thread-safe, you can use a thread-safe version, Tthreadlist, instead of tlist.
VCL thread is not secure