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

--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to