Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-18 Thread Tony Whyman
On 18/08/16 10:53, Graeme Geldenhuys wrote: I think you are getting confused between TObject and TInterfaceObject instances, and what is required from both. No, the problem is that I could not find a way of achieving what I wanted to achieve. That is ensuring that an interfaced object that used

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-18 Thread Graeme Geldenhuys
On 2016-08-10 16:47, Tony Whyman wrote: > You are explicitly freeing MyClass. My point is that with reference > counted interfaces and in the example I posted, you shouldn't have to > explicitly free the delegated interface. It should be freed > automatically as soon as it goes out of scope. Le

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted [Solved]

2016-08-17 Thread Marcos Douglas
On Wed, Aug 17, 2016 at 1:03 PM, Tony Whyman 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 interfa

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted [Solved]

2016-08-17 Thread Tony Whyman
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 or

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-10 Thread Tony Whyman
Graeme, You are explicitly freeing MyClass. My point is that with reference counted interfaces and in the example I posted, you shouldn't have to explicitly free the delegated interface. It should be freed automatically as soon as it goes out of scope. Tony Whyman MWA On 10/08/16 16:43, Gr

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-10 Thread Graeme Geldenhuys
On 2016-08-10 13:42, Tony Whyman wrote: > In the example, TMyClass is the interface class doing the delegation and > while TDelegateClass is being destroyed when it goes out of scope, > TMyClass is not. Maybe I'm missing something, but here is a quick example I put together. Testing with FPC 2.6

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-10 Thread Marcos Douglas
On Wed, Aug 10, 2016 at 11:08 AM, Tony Whyman wrote: > On 10/08/16 15:05, Marco van de Voort wrote: >> >> The way how Tony passes owner is wrong and that messes up reference >> counting. >> >> If in the test he would do TMyclass.Create(Tsomeclass.create); it >> probably >> would be ok. > > > But

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-10 Thread Tony Whyman
On 10/08/16 15:05, Marco van de Voort wrote: The way how Tony passes owner is wrong and that messes up reference counting. If in the test he would do TMyclass.Create(Tsomeclass.create); it probably would be ok. But in my test, the code reads: Intf := TMyClass.Create(TDelegateClass.Create)

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-10 Thread Marco van de Voort
In our previous episode, Marcos Douglas said: > On Wed, Aug 10, 2016 at 10:04 AM, Tony Whyman > > Destroying FMyInterface in the destructor does not make a difference - > > mainly because the TMyClass destructor is not being called anyway. > > It should be called, but is not. Strange. > I tried to

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-10 Thread Marcos Douglas
On Wed, Aug 10, 2016 at 10:04 AM, Tony Whyman wrote: > > ... > > Destroying FMyInterface in the destructor does not make a difference - > mainly because the TMyClass destructor is not being called anyway. It should be called, but is not. Strange. I tried to change the code to not using Applicatio

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-10 Thread Tony Whyman
On 10/08/16 13:57, Marcos Douglas wrote: Hi, See the "problem" bellow: TMyClass = class(TInterfacedObject, IMyInterface) private FMyInterface: TDelegateClass; <<< HERE >>> property MyInterface: TDelegateClass read FMyInterface implements IMyInterface; public co

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-10 Thread Tony Whyman
Marcos, Thanks for the suggestions, but I had already tried the first variation: TMyClass = class(TInterfacedObject, IMyInterface) private FMyInterface: IMyInterface; // class type property MyInterface: IMyInterface read FMyInterface implements IMyInterface; public

Re: [fpc-pascal] Delegate Interface class does not seem to be referenced counted

2016-08-10 Thread Marcos Douglas
Hi, See the "problem" bellow: TMyClass = class(TInterfacedObject, IMyInterface) private FMyInterface: TDelegateClass; <<< HERE >>> property MyInterface: TDelegateClass read FMyInterface implements IMyInterface; public constructor Create(obj: TDelegateClass); destr