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

Marc Weustink weus at quicknet.nl
Thu Aug 12 14:49:54 EDT 1999


Watching this thread I see some possible "misunderstandings" about a
control owner and a control parent.
The control owner is the delphi object owner. If the owner gets destroyed,
the control gets destroyed. When you create a control, you pass the owner.
At this point the control has no parent and the windows part of it is not
yet created. (refering to the windowshandle causes an exeption).

The control parent is the "graphical owner" or "Windows owner". So if you
move the parent, the control is moved as wel (as a part of the parent).
When a parent is set, the Windows part of the control is created as soon as
the handle is needed.

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;


HtH
Marc



At 21:54 11-08-99 -0700, "Shane Miller" <smiller at lakefield.net> wrote:
>
>
>The button is created in the Forms OnCreate?  The Button is created where
>ever the user puts the Button := TButton.Create(Owner).  Owner is set to the
>Form that the TButton is owned by.
>
>If the stdcontrols (or where ever the TButton class is defined) it should
>eventually call SendMessage3 sending the SELF (which in this case is the
>button).
>
>The button should have it's parent assigned already in Control.Create or
>TWinControl.Create.
>You may need to look at the difference of "owner" and "Parent".  Parent is
>used in TControl to hold the TWinControl I believe, so I think you should
>use owner.
>
>If Owner is set in TControl's create (which is called whne tbutton calls the
>inherited creates) then by the time the sendmessage is called, FOwner is
>set.
>
>In win32int.pp (or whatever) you recieve this message (LM_CREATE) call
>Createcomponent.  When you case the fcompstyle and determine it's a
>csButton, you can also check TControl(data).Owner.handle (or whatever) to
>get it's owners handle.
>
>Shane
>
>
>_________________________________________________________________
>     To unsubscribe: mail lazarus-request at miraclec.com with
>                "unsubscribe" as the Subject
>    archives at http://www.miraclec.com/list_archives/lazarus
>






More information about the Lazarus mailing list