Say my form is delared as TFormOther = class(TForm, IMyInterface)
where
type
IMyInterface = interface
['{50E7E215-A8EA-4A1C-9F1E-018E4A76DCBD}']
procedure DoSomething;
end;
and
TFactory = class(TInterfacedObject)
public
procedure MakeIt;
end;
procedure TFactory.MakeIt;
var
LMyIntf: IMyInterface;
begin
LMyIntf := TFormOther.Create(nil);
LMyIntf.DoSomething;
// (LMyIntf as TFormOther).Free; This is wrong and gives the classic:
// FastMM has detected an attemp to use an interface of a freed object.
end;
If I don't free the TFormOther instance I leak memory.
I know I can do Action := TCloseAction.caFree
in TFormOther.FormClose
but is that the only and best way?
This Will an interface-implementing form free itself when there are no more references to it? helped a lot but did not say how one should free the form.