This will work fine as long as you inherit from the class below at the top (bottom?) of your hierarchy. This code ensures that your new classes dont free themselves - as is the default behaviour of TInterfaceObject - you are presumably already freeing them yourself and want to preserve this. This activity is actually exactly what TComponent in the VCL does - it supports interfaces but is not reference counted.
type
TYourAncestor = class( TInterfacedObject )
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
end;
implementation
function TYourAncestor.QueryInterface(const IID: TGUID; out Obj): HResult;
const
E_NOINTERFACE = HResult($80004002);
begin
if GetInterface(IID, Obj) then Result := 0 else Result := E_NOINTERFACE;
end;
function TYourAncestor._AddRef: Integer;
begin
Result := -1 // -1 indicates no reference counting is taking place
end;
function TYourAncestor._Release: Integer;
begin
Result := -1 // -1 indicates no reference counting is taking place
end;