急!(100分)

  • 主题发起人 主题发起人 kenmen
  • 开始时间 开始时间
K

kenmen

Unregistered / Unconfirmed
GUEST, unregistred user!
请问CREATE,FREE,EXCUTE有啥不同,
怎用?
 
什么意思
 
要看什么对象
 
create创建
free 释放
excute运行?
 
顾名思义。前两个配对使用和最后一个关系好像不大
 
各位大侠,能说举体点吗?
 
你是不是想要例子呀!!
 
没法说得更<font color =#ff0000><strong>举体</font></strong>了。
其实 kenmen 应该先自己看看书再提问的,这个问题怎么说,是不是太 unprofessional 了?
 
区别太大了,一般来说,运行时程序中生成一个控件的话,要用到CREATE,比如这样一段代码:
var
myimage:TImage;
begin
myimage:=TImage.create
//这里用一个TOBJECT的来做说明
...
当然,有创建必须有释放,当然,有很多时候你不用自己释放,DELPHI自己能管理内存,
但最好像这种自己运行时创建的还是自己在程序中释放。释放有两种方法free和destroy。
在DELPHI的帮助中两者的区别是DESTROY:Disposes of an object instance.(在内存中销毁
一个TOBJECT的实例)
FREE:Destroys an object and frees its associated memory, if necessary.
除了要DESTROY外,FREE还会把已分配的内存收回。唔,照我的理解,一个TOBJECT被DESTROY后
原先它所占用的内存空间现在还是被标为不能被其它东东所用,它只是Disposes了这个OBJECT
的实例而已;而FREE后,除了把这个OBJECT的实例给Disposes了外,还要把它所占用的内存空间
收回,让别的OBJECT什么的也可以使用这部分内存空间。突然想到一点,不知在用了DESTROY后
再CREATE后,这个OBJECT是不是还会占用它上次CREATE时的内存所在呢?
至于EXCUTE,还没用过,不过倒是知道TQUERY对象可以用这个来执行SQL语句!^_^




 
create 是创建一个对象或目标!如创建一个控件等
Free 就是释放先前创建的元件,也就是释放其占用的资源。
EXECUTE 一般用在诸如数据控件、对话框等元件的执行上。
 
Form1.Create(self) 创建对象
Form1.Free 释放对象
MyClientDataSet.Execute 执行CommandText

Declaration
constructor Create(aOwner: TComponent);

Description
The Create method allocates memory to create the component and initializes its
data as needed. The owner of the created component is passed in the aOwner
parameter.

You seldom need to call Create. Objects designed with ReportBuilder create and
destroy themselves as needed, so you don't have to worry about it. If you
construct an object by calling the Create method, you should call Free to
release memory and dispose of the object.

Destroys an object and frees its associated memory, if necessary.

procedure Free;

Description

Use Free to destroy an object. Free automatically calls the destructor if the
object reference is not nil. Any object instantiated at runtime that does not
have an Owner should be destroyed by a call to Free, so that can be properly
destroyed and the memory released. Unlike Destroy, Free is successful even if
the object is nil, so if the object was never initialized, Free won抰 result
in an error.

When you call Free for a component, it calls Free for all components that it
owns, that is, all components in its component list. A form owns all the
controls and non-visual components that are created on it in design mode.
When it is freed, all of these components are automatically freed as well.
Since, by default, all forms are owned by the Application object, when the
application terminates, it frees the Application object, which frees all
forms. For all objects that are not components, or for components created
with a nil owner, be sure to call Free after you are finished with the object

otherwise the allocated memory will not be usable until after the application
terminates.

Warning: Never explicitly free a component within one of its own event handlers
or free a component from the event handler of a component it owns or contains.
For example, don抰 free a button in its OnClick event handler or free the form
that owns the button from the button's OnClick event.

To free a form, call its Release method, which destroys the form and releases
the memory allocated for it after all its event handlers and those of the
components it contains are through executing.



 
多人接受答案了。
 
后退
顶部