__property implements Support in C++Builder
Go Up to C++ Specifics Index
C++Builder introduces the implements
attribute for the __property
keyword. The implements
attribute enables you to implement interfaces efficiently, without involving multiple inheritance. In the past, classes based on TObject were allowed to implement interfaces. However, implementing interfaces in C++ was tedious compared to Delphi, primarily because of the way multiple inheritance works in C++ (see Implementing Interfaces: Delphi and C++).
The implements Attribute Is Helpful for Using DAX: The __property implements
has the following advantages for ActiveX:
- Enables a C++ class to easily use the ActiveX helpers provided by DAX (Delphi ActiveX, the new framework for ActiveX in C++Builder XE).
- Makes it easier for C++Builder XE ActiveX projects to make the transition from ATL to DAX.
The implements
attribute of the C++ __property
keyword allows
you to implement an interface by specifying it as an attribute or field of a class. This implementation is analagous to how the Delphi implements
directive allows a class to implement an interface by delegating to a property.
In a __property
statement, the implements
attribute is placed last, similar to the placement of the __nodefault
attribute.
Syntax of __property implements
Here is the syntax of the implements
attribute of the __property
keyword:
class TMyPersist: public TInterfacedObject
{
IPersist* FPersist;
public:
__property IPersist* Persist = {read=FPersist, write=FPersist, implements};
};
The syntax omits the initialization of the FPersist field. The class constructor might initialize FPersist to some DAX helper for IPersist.
In response to the implements
attribute, the C++ compiler records the interface (IPersist, in this case) in the InterfaceTable of the RTTI for TMyPersist (as well as the offset of the FFooBar field).
Note: The
__property implements
attribute works only with fields, not with getters or setters.
For a full code example, see Implementing Interfaces: Delphi and C++.