Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-05

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

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

cobines

Hello.

In TWinControl.Destroy there is code:

  while n > 0 do
  begin
    Control := Controls[n - 1];
    Remove(Control);   <--
     ...
    Control.Parent := nil; <--
    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?

cobines
Mattias Gaertner
to cobines
Show quoted text 10 lines
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.

Show quoted text 24 lines
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

cobines
to Mattias Gaertner

2011/5/23 Mattias Gaertner :

Show quoted text 15 lines
On Mon, 23 May 2011 22:07:58 +0200 cobines 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.

OK. Thanks!

cobines