在窗体的CREATE事件里如何FREE掉本窗体?(50分)

P

panjf

Unregistered / Unconfirmed
GUEST, unregistred user!
呵呵,
Form1.Free;

你编译运行以后什么也看不见~~~
 
self.free;
 
self.free;
 
sendmessage(self.handle,WM_CLOSE,0,0);
 
应该会出错吧。。。
在CREATE事件里就FREE,我是试过在SHOW事件里HIDE,运行时提示出错,不能在SHOW事件里
HIDE。。。
 
在CREATE里好象是不可以FREE在吧!
不过如果你想结束退出的话,可以这样!
APPLICATION.TERMINATE;
 
1、窗体在创建前是不能释放掉的。
2、其实你如果不要窗体的话起步简单,在工程文件中加入你的代码,然后去掉工程的窗体。
如下。前提是你确实不需要该窗体

program Project1;

uses
windows,sysutils,forms;

{$R *.RES}

begin
Application.Initialize;
//add your code in here
......
Application.Run;
end.
 
在窗体事件中是不能Free窗体的,必须使用Release方法。
例:
Form1.Release;
 
那个窗体不是主窗体,真的没有办法吗?
 
那里為什么要執行create? 是用到了類的繼承嗎?
寫在OnActivate吧﹐ 且frmForm1:=nil
我想應該可以。
 
在Create事件中怎么可能释放自己,这时对象都没有建立,用free的话会出现非法访问错误。
 
postmessage(self.handle,WM_CLOSE,0,0)
测试通过,撒分吧!!!
 
我同意教父的意见,我曾经也遇到过这样的问题。自己是不能释放自己的。换种方式!
 
我倒,你是要运行中自己使那个窗体CREATE吧。先选择"project"菜单中的"option",然后在
FORMS那,把你要以后再CREATE的窗体从"Auto-create forms:"列表中移到"Available forms"
列表中去。
然后在程序中,当你要创建这个窗体时,这样:
代码:
form2:=tform2.create(application);
form2.show;
 
CREATE事件不能FREE自己,如果要做只能用该事件TIGER其它的事件或消息去做
 
Destroys the form and frees its associated memory.

procedure Release;

Description

Use Release to destroy the form and free its associated memory.

Release does not destroy the form until all event handlers of the form and event handlers of components on the form have finished executing. Release also guarantees that all messages in the form's event queue are processed before the form is released. Any event handlers of the form should use Release instead of Free. Failing to do so could lead to an access violation.

Note: Release returns immediately to the caller. It does not wait for the form to be freed before returning.
 
self.Release
 
你不是要做~~~~~;)
要不显示主窗体
Application.showmainform:=false;

如要中止非主窗体,不显示
sendmessage(handle,WM_CLOSE,0,0);
 
顶部