parent 与owner的含义区别及举例

parent即 养父
是指拥有该组件的父类,即parent组件必定是一个窗口控制组件(Windowed control) 由于组件就是容纳该组件的父类,因此当父类移动时,附着其内的组件也会移动.
 Object TreeVIew 里表示的就是这种关系.
 1 unit  Unit1;
 2
 3 interface
 4
 5 uses
 6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 7   Dialogs, StdCtrls;
 8
 9 type
10   TForm1  =   class (TForm)
11     GroupBox1: TGroupBox;
12     Button1: TButton;
13     Button2: TButton;
14     Button3: TButton;
15     Button4: TButton;
16     Button5: TButton;
17      procedure  Button5Click(Sender: TObject);
18      procedure  Button3Click(Sender: TObject);
19      procedure  Button4Click(Sender: TObject);
20      procedure  FormCreate(Sender: TObject);
21    private
22      {  Private declarations  }
23    public
24      {  Public declarations  }
25    end ;
26
27 var
28   Form1: TForm1;
29
30 implementation
31
32 uses  Unit2;
33
34 VAR
35   PB: boolean;
36 { $R *.dfm }
37
38 procedure  TForm1.Button5Click(Sender: TObject);
39 begin
40 Form2.show
41 end ;
42
43 procedure  TForm1.Button3Click(Sender: TObject);
44 begin
45 GroupBox1.Top : =  GroupBox1.Top  -   10 ;
46 end ;
47
48 procedure  TForm1.Button4Click(Sender: TObject);
49 begin
50    if  PB  then
51   BEGIN
52     Button2.Parent : =  Form2;
53     PB : =  false;
54   END
55    else
56   BEGIN
57     Button2.Parent : =  Form1.GroupBox1;
58     PB : =  true;
59   END;
60 end ;
61
62 procedure  TForm1.FormCreate(Sender: TObject);
63 begin
64 Pb : =   false;
65 end ;
66
67 end .
68
69

Owner  生父 
 何谓Owner?就组件而言 , Owner是指作为其他组件的Owner的父组件,在负责自身 析构时,一起析构它所拥有的其下所Own的组件,也就是于此时释放它自己与它所拥有 组件所占的内存.
 1 unit  Unit1;
 2
 3 interface
 4
 5 uses
 6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 7   Dialogs, StdCtrls;
 8
 9 type
10   TForm1  =   class (TForm)
11     Edit1: TEdit;
12     Button1: TButton;
13     Button2: TButton;
14      procedure  Button2Click(Sender: TObject);
15    private
16      {  Private declarations  }
17    public
18      {  Public declarations  }
19    end ;
20
21 var
22   Form1: TForm1;
23
24 implementation
25 uses
26  unit2;
27 { $R *.dfm }
28
29 procedure  TForm1.Button2Click(Sender: TObject);
30 begin
31 Form2.show
32 end ;
33
34 end .
35
36

转载于:https://www.cnblogs.com/dreamszx/archive/2009/09/22/1572004.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值