zoukankan      html  css  js  c++  java
  • Delphi中Owner和Parent的区别

    Delphi中Owner和Parent的区别
    Owner为创建者,Parent为容器 他们的类型不同,Owner为TComponent(元件),Parent为TWinControl(窗体控件)

    Parent属性是指构件的包容器,构件只能在此范围内显示和移动。举例子如下:
    (1)在Form1的窗体上,放一个Panel1,并将Panel1拉大,
    (2)在Panel1上放一Button1;
    (3)在Form1上放一Button2。

    现在如果移动Panel1,则Button1随着Panel1移动,这是因为Button1的Parent是Panel1。现在将Button2移到 Panel1上,再次移动Panel1,Button2并不跟着移动,这是因为Button2的Parent是Form1。除在窗体设计中,应注意构件的 Parent是谁外,在动态创建构件时,也应指出构件的Parent,如在上例中继续操作:
    1)Procedure Tform1.Button2click(Sender:Tobjet);
    2)Var
    3) Button:Tbutton;
    4) Begin
    5) Button:Tbutton.cerate(self);
    6) Button.parent=panel1;
    7) Button.lleft=0;
    8) Button.top=0;
    9) Button.caption:=’OK’;
    10) End;

    当按Button2时,将在Panel1上创建一个Button,而如果把第6句改为Button.parent:=self;按Button2时, 将在Form1上创建一个Button了。如果将第6句删除,按Button2时,什么都不会发生,这是因为创建方法无法知道应在哪里显示构件。

    Owner属性是指构件的所有者,它负责构件的创建和释放。如在上例中,系统默认窗体上所有构件的所有者是窗体,而窗体的所有者是 Application。顺便指出,create方法应带有表示构件所有者的参数,如在上例中,构件所有者是窗体,即self。

    Parent属性和Owner属性是运行阶段的属性,只能在运行阶段,通过代码设置。

    Owner为创建者,Parent为容器 他们的类型不同,

    Owner为TComponent(元件),Parent为TWinControl(窗体控件)

  • 相关阅读:
    poj 3636
    poj 1065 Wooden Sticks
    2017北京国庆刷题Day6 afternoon
    2017北京国庆刷题Day5 afternoon
    2017北京国庆刷题Day3 afternoon
    2017北京国庆刷题Day3 morning
    2017北京国庆刷题Day2 afternoon
    2017北京国庆刷题Day2 morning
    poj2420 A Star not a Tree?
    NOIP2016 愤怒的小鸟
  • 原文地址:https://www.cnblogs.com/xunmengyoufeng/p/2964553.html
Copyright © 2011-2022 走看看