My Environment:
OS - Windows7 Pro(32bit)
IDE - RadStudio XE2 Update4
I am wondering about Synchronize() function.
The Synchronize() function is used in the thread program. About using the Synchronize() in C+ builder, the example is as follows ( as can be seen in here)
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(&UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall TMyThreadClass::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
What I am confused is that , in some older version of C++ builder (e.g. bcb6), the Synchronize() was used
// Synchronize(UpdateCaption);
without "&" before the function name;
Also in the delphi code as in here, there is no "&" before the function name;
// Synchronize(UpdateCaption);
So, which is the correct way to use Synchronize() in C++ builder
// Synchronize(UpdateCaption);
or
// Synchronize(&UpdateCaption);
I tried both in the actual code, but seems identical in the working manner. Do both UpdateCaption and &UpdateCaption return address of functions?
UpdateCaptionand&UpdateCaptionare illegal. It's a C++Builder extension that, for a member function,&UpdateCaptionevaluates to a__closure, which is a pointer to the combination of an object and a member function on that object. (C++11 added closures to the language; however C++Builder predates that by a long way, so they had to add their own extension for it). Apparently there is also a feature thatUpdateCaptionimplicitly converts to&UpdateCaptionin overload resolution, although it doesn't do so on its own! (e.g.UpdateCaption;gives an error). - M.MSynchronize()(and events) specifically rely on Borland's__closureextension, which is much more flexible than a MFP. A MFP is specific to a particular class. A closure is not, which makes it possible to assign different classes to the same pointer-to-member variable. - Remy Lebeau&FunctionNamedoes not work in Standard C++. To get a MFP you have to write&ClassName::FunctionName. - M.M