This page is intended as a supplement to the official documentation on Delphi programming. CodeGear is in the process of putting the Delphi documentation on the Web. Once they have done so, this page will link to the relevant page in the official documentation.
This article is a stub.
Please help enhance the Delphi Programming Wiki by expanding it.
see the VCL Documentation Guidelines for an overview on doc pages




(Please provide a description in your own words. It is illegal to use the wording from the Delphi Help.)

Technical CommentsEdit

(Known issues / Documentation clarifications / Things to be aware of)

Synchronize methodEdit

The TThread.Synchronize method is available in three overloaded versions (Delphi 2007):

   class procedure Synchronize(ASyncRec: PSynchronizeRecord; QueueEvent: Boolean = False); overload;
   procedure Synchronize(AMethod: TThreadMethod); overload;
   class procedure Synchronize(AThread: TThread; AMethod: TThreadMethod); overload;

  • The first version is private and therefore only used internally.
  • The second version is meant to be called from within the thread object itself.
  • The third is a class method to be called from outside and therefore needs the thread object as the first parameter. This parameter can be nil, though.

There is also a StaticSynchronize method, that just calls the third version and has the same parameters.

The method is used to execute a method in the context of the application's main thread, e.g. to access the (non-threadsafe) VCL. For this it uses a rather complicated approach that on the other hand seems to be faster and more reliable than most other solutions I have seen (in particular it is faster than using PostMessage). The implementation of TThread.Synchronize has changed several times over the years.

To avoid a deadlock, you must make sure that your main thread is able to execute its message loop when Synchronize is being called. If that's not possible, call the procedure CheckSynchronize like this:

 // Called in the main thread, it is assumed that the
 // Thread sets SomeThread to nil when it terminates.
 while Assigned(SomeThread) do

(Alternatively you can call SomeThread.WaitFor, the above is just an example.)


(Please provide links to articles/source code that show how to use this item.)

See AlsoEdit

(Please provide links to items specifically related to this item.)

User Comments/TipsEdit

(Please leave your name with your comment.)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.