Multiple interfaces

Top  Previous  Next

What is translated > Types > Records, Classes, Interfaces > Multiple interfaces

In Delphi a class can be derived from multiple interfaces. Interfaces in last instance have to be derived from IInterface, which in Delphi is the same as IUnknown, C++ however uses IUnknown from MS Windows, which has the abstract methods: AddRef, Release and QueryInterface. In Delphi analogous methods are defined automatically, when a class is derived from Delphi's IInterface (=IUnknown). In C++ however, the implementations have to be defined explicitly. Therefore a macro is inserted into class declaration:

 

#define INTFOBJECT_IMPL_IUNKNOWN(BASE) \

   ULONG   __stdcall AddRef() { return BASE::AddRef();} \

   ULONG   __stdcall Release(){ return BASE::Release();} \

   HRESULT __stdcall QueryInterface(REFIID iid, void** p){ return BASE::QueryInterface(iid, p);}

 

An class declaration then for example looks like:

 

class TCar : public System::TInterfacedObject, public IRecyclable

{

public:

INTFOBJECT_IMPL_IUNKNOWN(System::TInterfacedObject)

...

 

 

More details to this subject can be found here:

 

http://docwiki.embarcadero.com/RADStudio/Rio/en/Inheritance_and_Interfaces

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content