delphiparent:Delphi中Owner和Parent的区别来源: 发布时间:星期四, 2009年2月12日 浏览:170次 评论:0
Parent属性是指构件包容器构件只能在此范围内显示和移动举例子如下: (1)在Form1窗体上放个Panel1,并将Panel1拉大 (2)在Panel1上放Button1; (3)在Form1上放Button2 现在如果移动Panel1,则Button1随着Panel1移动这是Button1Parent是Panel1现在将Button2移到Panel1上再次移动Panel1,Button2并不跟着移动这是Button2Parent是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属性是运行阶段属性只能在运行阶段通过代码设置 0
相关文章
读者评论发表评论 |
|