请问他们的区别是什么?(30分)

J

jmsczb

Unregistered / Unconfirmed
GUEST, unregistred user!
在下在编程时遇到过窗体生成时的不同写法:
1 Form1:=Tform1.create(application);
2 Form1:=Tform1.create(self);
3 Form1:=Tform1.create(nil);
请高手指点,我可是刚入门的呀.不明白的大虾可不要蒙俺呀:)
 

冰 原

Unregistered / Unconfirmed
GUEST, unregistred user!
D

Dephic

Unregistered / Unconfirmed
GUEST, unregistred user!
1 Form1:=Tform1.create(application);//说明这个Form对象所有者是Application
2 Form1:=Tform1.create(self);//说明这个Form对象所有者是自己
3 Form1:=Tform1.create(nil);//说明这个Form对象不属于任何对象
 
J

jmsczb

Unregistered / Unconfirmed
GUEST, unregistred user!

能否具体的说一下这3者的区别?application的对象是谁,是form的上级吗?
 
L

lbsong

Unregistered / Unconfirmed
GUEST, unregistred user!
establishes the relationship of a component and its Owner, as indicated by the AOwner parameter
以前对这个问题都是自己的理解,乘这个机会,专门去查了一下帮助,看了以后,我们可以知道,当你
create一个form或者任何继承自tcomponent的控件的时候,Delphi建立了这个控件和owner的关系,
The owner disposes of the component when it is destroyed. If the component is not owned,
then
use Free when it needs to be destroyed.
然后当owner释放的时候由这个owner释放这个component,如果这个component释放没有owner
那么,它不会被释放,需要用户来手动释放;
对于self由
Within the implementation of a method, the identifier Self references the object in which the method is called
可知self表示方法所在的对象
综上所述:
1.form由应用程序来释放,当程序退出时,自动释放form
2.form由本身来释放
3.form由用户来释放
 
J

jmsczb

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
J

Jhdandcl

Unregistered / Unconfirmed
GUEST, unregistred user!
在Delphic 基础上加点.
1 Form1:=Tform1.create(application);//说明这个Form对象所有者是Application
系统分配给Form1的资源有两种free方式,1,Form1 自己FREE,2.当Application Free前,
会检查form1,如果分配的资源没free,则帮其FREE。
2 Form1:=Tform1.create(self);//说明这个Form对象所有者是自己
系统分配给Form1的资源有1种free方式,1.Form1 自己FREE。
3 Form1:=Tform1.create(nil);//说明这个Form对象不属于任何对象
系统分配给Form1的资源必须有你去FREE。即你要加一句Form1.free
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
474
import
I
顶部