Reputation: 21154
The manual says that Synchronize is a member of TThread. However it shows that you can call Synchronize directly. Other sources tell the same.
//Synchronize() performs actions contained in a routine as if they were executed from the main VCL thread
void __fastcall TCriticalThread::Execute()
{
...
Synchronize(UpdateCaption);
...
}
But if I do this, my compiler tells me "E2268 Call to undefined function 'Synchronize'". Of course I included the library:
#include <System.Classes.hpp>
On the other hand, TThread::Synchronize is found by the compiler, but it does not accept MainThreadID as parameter:
TThread::Synchronize(MainThreadID, MainForm->UpdateCaption );
PS: I am new to C++ Builder.
Upvotes: 2
Views: 2484
Reputation: 596352
Synchronize()
is a method of the RTL's TThread
class. In all versions of C++Builder, TThread
has a non-static version of Synchronize()
, which is the version the code you showed is trying to call. That requires TCriticalThread
to be derived for TThread
, eg:
class TCriticalThread : public TThread
{
...
protected:
virtual void __fastcall Execute();
...
};
void __fastcall TCriticalThread::Execute()
{
...
Synchronize(UpdateCaption);
...
}
If that is not the case in your situation, TThread
also has a static version of Synchronize()
that can be used with threads that are not derived from TThread
, eg:
void __fastcall TCriticalThread::Execute()
{
...
TThread::Synchronize(NULL, UpdateCaption);
...
}
Upvotes: 6