unit Myc.Utils; interface type TManaged = record private type TObj = class(TInterfacedObject) FValue: T; constructor Create(AValue: T); destructor Destroy; override; end; var FIntf: IInterface; public class operator Implicit(A: T): TManaged; overload; class operator Implicit(const Upvalue: TManaged): T; overload; end; TGenericContainedObject = class(TObject, IInterface) private FController: TInterfacedObject; protected function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall; function _AddRef: Integer; stdcall; function _Release: Integer; stdcall; property Controller: TInterfacedObject read FController; public constructor Create(AController: TInterfacedObject); end; implementation constructor TManaged.TObj.Create(AValue: T); begin inherited Create; FValue := AValue; end; destructor TManaged.TObj.Destroy; begin FValue.Free; inherited; end; class operator TManaged.Implicit(A: T): TManaged; begin Result.FIntf := TObj.Create(A); end; class operator TManaged.Implicit(const Upvalue: TManaged): T; begin Result := (Upvalue.FIntf as TObj).FValue; end; constructor TGenericContainedObject.Create(AController: TInterfacedObject); begin inherited Create; FController := AController; end; { TGenericContainedObject } function TGenericContainedObject.QueryInterface(const IID: TGUID; out Obj): HResult; begin if GetInterface(IID, Obj) then Result := S_OK else Result := E_NOINTERFACE; end; function TGenericContainedObject._AddRef: Integer; begin Result := IInterface(FController)._AddRef; end; function TGenericContainedObject._Release: Integer; begin Result := IInterface(FController)._Release; end; end.