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

Marcos Douglas md at delfire.net
Wed Aug 10 16:37:14 CEST 2016


On Wed, Aug 10, 2016 at 11:08 AM, Tony Whyman
<tony.whyman at mccallumwhyman.com> 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 in my test, the code reads:
>
>    Intf := TMyClass.Create(TDelegateClass.Create);
>
> So, why didn't this work?

+1
Is the same as Michael wrote.

[off]
Tony,

You need to be careful when you use Interfaces and constructions like above.
Using constructions like that, you always need to remember:
"Now I need a local variable to the compiler do the refcount..."
"Here isn't necessary, because the argument is an interface type variable..."
...and so on.

For this "problem" I have my own pattern. I wrote about it here
http://objectpascalprogramming.com/posts/interfaces-e-o-metodo-estatico-new/
I write in Portuguese, but you can translate easily.
[/off]

Marcos Douglas



More information about the fpc-pascal mailing list