Owners and Parents Was: Re: [lazarus] Creating Components...

Marc Weustink weus at quicknet.nl
Fri Aug 13 13:06:52 EDT 1999


At 00:41 13-08-99 -0400, "Jeffrey A. Wormsley" <daworm at cdc.net> wrote:
>>For instance if you execute the following in a OnCreate event an instance
>>of the button is created, but no Graphical/Windows part.
>>  TButton.Create(Self);
>>
>>If you pass a parent, the graphical part gets created as well.
>>  TButton.Create(Self).Parent := Self;
>
>How is this supposed to be handled?  If I understand correctly, windows
>will automatcally destroy any window children when the parent destroy is
>called.  

Thats correct. The windows part at least, the delphi object part should be
don by delphi (of course ;-)

>If you create a window with no parent, this does not happen.  

You create the delphi object (like line 1) so then next construction is
complete valid.

1: b := TButton.Create(Self);
2: p := TPanel.Create(Self);
3: b.Parent := p;
4: p.Parent := Self;

line 1 and 2 creates the objects, line 3 tells the button that its parent
is the panel. The buttonchecks if his parent has a windows handle. This is
not the case so nothing happens.
Line 4 tells the panel that its parent is the form. The form has a handle
--> every Windows part is created.

If you lateron somewhere in your code change parent, the windows part is
moved to the new parent:

5: p2 := TPanel.Create(Self);
6: p2.Parent := Self;
7: b.Parent := p2;

Now the button is part of the second panel (and all are still owned by your
form)

>How
>do you, after the create, tell a window that it has a parent, when it did
>not have one when it was created?

like line 3 and 4.


Marc








More information about the Lazarus mailing list