Quick response
Your interface must have a GUID for the operator as. Go to the first line after IMyInterface = interface, before any method definitions, and press Ctrl+ Gto generate a new GUID.
as GUID, IUnknown.QueryInterface, GUID. , INTERFACE INTERFACE.
TInterfacedObject , , - (TInterfacedObject), (IMyInterface). , : TObject , - .Free; , .Free . : , , ( - ), . ZERO, (.Free)!
- , :
procedure DoSomething(If: IMyInterface);
begin
end;
procedure Test;
var O: TMyObjectImplementingTheInterface;
begin
O := TMyObjectImplementingTheInterface.Create;
DoSomething(O); // Works, becuase TMyObject[...] is implementing the given interface
O.Free; // Will likely AV because O has been disposed of when returning from `DoSomething`!
end;
: O TMyObject[...] IMyInterface, :
procedure DoSomething(If: IMyInterface);
begin
end;
procedure Test;
var O: IMyInterface;
begin
O := TMyObjectImplementingTheInterface.Create;
DoSomething(O); // Works, becuase TMyObject[...] is implementing the given interface
end; // `O` gets freed here, no need to do it manually, because `O` runs out of scope, decreases the ref count and hits zero.