[Lazarus] Something the examine Lazarus or applications?

Ondrej Pokorny lazarus at kluug.net
Mon Jan 11 18:55:54 CET 2016


On 11.01.2016 18:26, Bart wrote:
> That would lead to crashes all over the place:
>
> C:=TComponent.Create(nil);
> try
> ...
> finally
>    C.Free;
> end;
>
> Upon app termination the Application object would the again try to
> free C (note: it is not nil) -> Access Violation.

No, you are also wrong :) The owner is detached in the destructor. See:

Destructor TComponent.Destroy;
[...]
   If FOwner<>Nil Then FOwner.RemoveComponent(Self);
   inherited destroy;
end;

Of course this works:

C:=TComponent.Create(Application);
try
...
finally
   C.Free;
end;

Ondrej




More information about the Lazarus mailing list