I need a special entry with an interface.
and the interface has a child interface and some class. therefore, automatic release is needed. but, the interface in the recording is already released.
need help, why is linkmatch missmatch?
I try the following code ...
// --------------------------------------------- --- --------------------
type IIn = interface procedure SetValue(v : string); function AsString() : string; function GetChild() : IIn; end; RIn = record FIn : IIn; procedure SetInterface(intf : IIn); procedure SetValue(v : string); function AsString() : string; function GetChild() : RIn; end; TIn = class(TInterfacedObject, IIn) private FChild : IIn; FValue : string; public procedure SetValue(v : string); function AsString() : string; function GetChild() : IIn; end;
// --------------------------------------------- --- --------------------
procedure RIn.SetInterface(intf : IIn); begin FIn := intf; end; function RIn.GetChild() : RIn; var childInterface : IIn; begin if FIn = nil then FIn := TIn.Create(); childInterface := FIn.GetChild(); Result.SetInterface( childInterface ); end; procedure RIn.SetValue(v : string); begin if FIn = nil then FIn := TIn.Create(); FIn.SetValue(v); end; function RIn.AsString() : string; begin if FIn = nil then FIn := TIn.Create(); Result := FIn.AsString(); end; function RIn.GetRefCnt() : integer; begin if FIn = nil then FIn := TIn.Create(); Result := FIn.GetRefCnt(); end; procedure TIn.SetValue(v : string); begin FValue := v; end; function TIn.AsString() : string; begin Result := FValue; end; function TIn.GetChild() : IIn; begin if FChild = nil then FChild := TIn.Create(); Result := FChild; end;
// --------------------------------------------- --- --------------------
// global var var test : RIn; // test procedure 1 procedure test1; begin test.GetChild().SetValue('test...'); end; // test procedure 2 procedure test2; begin ShowMessage( test.GetChild().AsString ); <----- Error!! child interface is already released.. end;
source share