[fpc-devel] FreeNotification and opRemove

Martin lazarus at mfriebe.de
Thu Mar 8 14:34:43 CET 2012


On 08/03/2012 13:08, michael.vancanneyt at wisa.be wrote:
>
>
> On Thu, 8 Mar 2012, Martin wrote:
>
>> Further more:
>>
>> the program below, does not crash in delphi (turbo delphi)
>
> I also noticed. I suspect the problem is the owner; If it gets a free 
> notification, it should pass it to all the children.

I don't think that is it.

In the example below C1 is no longer owned, when C2 is destroyed, so the 
problem would persist.

The problem is that opRemove breaks the bi-directional bounding of 
FreeNotifications.

When C2 gets the opREmove, it must mot just remove it's own entry, but 
also remove the entry C1 has


>>
>> On 08/03/2012 09:56, Martin wrote:
>>>
>>> program Project1;
>>> {$mode objfpc}{$H+}
>>> uses  Classes;
>>> var
>>>   Owner, C1, C2: TComponent;
>>> begin
>>>   Owner := TComponent.Create(nil);
>>>   C1 := TComponent.Create(Owner);
>>>   C2 := TComponent.Create(Owner);
>>>
>>>   C1.FreeNotification(c2);
>>>
>>>   Owner.RemoveComponent(C1); // C2 Gets on opRemove
>>>   C2.Free;
>>>   C1.Free; // crash
>>>
>>>   ReadLn;
>>> end.
>>>




More information about the fpc-devel mailing list