Это будет работать нормально, если вы наследуете класс ниже в верхней (нижней части?) Вашей иерархии.Этот код гарантирует, что ваши новые классы не освобождают себя - как и поведение TInterfaceObject по умолчанию - вы, вероятно, уже освобождаете их сами и хотите сохранить это.Это действие на самом деле именно то, что делает TComponent в VCL - оно поддерживает интерфейсы, но не подсчитывает ссылки.
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;