RAD Studio VCL Reference
TInterfacedObject Class

System::TInterfacedObject is a base for simple classes that need a basic IInterface implementation.

TInterfacedObject = class(TObject, IInterface);
class TInterfacedObject : public TObject, public IInterface;

System::TInterfacedObject is a thread-safe base class for Delphi classes that support interfaces. System::TInterfacedObject provides basic reference-counting functionality that makes its descendant classes useful in both Delphi and C++ code.

Note: In Delphi, variables declared to be of type System::TInterfacedObject have dynamic-binding, meaning that an instance of a descendant class can be assigned to that variable at runtime. This is because System::TInterfacedObject implements System::TInterfacedObject::QueryInterface, which is called at runtime to query whether the instantiated object supports the requested interface. If it does, then the descendant object is successfully assigned to the variable. Without System::TInterfacedObject::QueryInterface support, such an assignment would produce a compile-time error.
Note: In Delphi, a descendant of System::TInterfacedObject does not have a class factories or a CLSID. Thus it cannot be instantiated except by calling a constructor.
Note: System::TInterfacedObject does not implement the methods of the C++ version of IUnknown or IInterface. This is not a problem when using C++ wrappers for System::TInterfacedObject descendants that are written in Delphi. However, if you are creating C++ descendants of System::TInterfacedObject, you must provide your own implementation of IUnknown. For information on how to do this, see Creating classes that support IUnknown (supplied with C++ products only).

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!