[Lazarus] In TWinControl.Destroy parent is NIL'ed twice for controls

Mattias Gaertner nc-gaertnma at netcologne.de
Mon May 23 22:51:18 CEST 2011


On Mon, 23 May 2011 22:07:58 +0200
cobines <cobines at gmail.com> wrote:

> Hello.
> 
> In TWinControl.Destroy there is code:
> 
>   while n > 0 do
>   begin
>     Control := Controls[n - 1];
>     Remove(Control);   <--
>      ...
>     Control.Parent := nil; <--

That one was not needed any more. I removed it.

>     n := ControlCount;
>   end;
> 
> In Remove() which is non-virtual:
> 
> procedure TWinControl.Remove(AControl : TControl);
> begin
>   if AControl <> nil then
>   begin
>     ...
>     AControl.FParent := nil;
>     ...
>   end;
> end;
> 
> So, first there is AControl.FParent := nil, then there is
> Control.Parent := nil. There is one too many.
> 
> Also, the first assignment is directly to variable bypassing virtual
> SetParent. The other uses property which calls SetParent but it
> doesn't do anything because Parent is already =nil.
> 
> Is it correct that Control.Parent can be removed? And which should be
> the correct version of assignment: using FParent  or Parent?

FParent is correct.

Mattias




More information about the Lazarus mailing list