On Wed, Aug 17, 2016 at 1:03 PM, Tony Whyman <tony.why...@mccallumwhyman.com> wrote: > I think that I have now found why the test program below (originally posted > a couple of weeks ago) did not work. It seems that when an interface is > delegated, the compiler may take a reference directly on the delegated part > of the interface and not to the object doing the delegation. > > In my original post, the main procedure was: > > procedure TDelegateTest.DoRun; > var Intf: IMyInterface; > Intf2: IMyInterface; > begin > Intf := TMyClass.Create(TDelegateClass.Create); > Intf2 := TDelegateClass.Create; > ... > > and the output showed that TMyClass was not being automatically destroyed. > Changing the local variables declaration to: > > procedure TDelegateTest.DoRun; > var Intf: IUnknown; > Intf2: IMyInterface; > > results in this output: > > Creating TDelegateClass > Creating TMyClass > Creating TDelegateClass > Destroying TMyClass > Destroying TDelegateClass > [...]
So, in that way you will need to use 'cast' to work with Intf1 variable because it is not a IMyInterface type, right? Sounds like a workaround to me, not a good solution. Maybe I may have missed something, but I still think this is a bug. Best regards, Marcos Douglas _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal