窗口切换(100分)

  • 主题发起人 主题发起人 sunny_sky
  • 开始时间 开始时间
S

sunny_sky

Unregistered / Unconfirmed
GUEST, unregistred user!
本人采用单文档界面做的程序。由一个窗口切换到另一个窗口,使用的代码是
main:=Tmain.Create(self);
main.Showmodal;
close;(切换到main窗口,同时关闭本窗口)
但为什么本窗口仍然没有关闭,只是隐藏在main窗口后面。如何才能真正关闭他呢?
 
在子窗口的onClose事件中写上
Action:= caFree;
肯定可以解决
 
因为showmodal时过程将暂停执行,即你在showmodal后直到showmodal的关闭,后面的
语句是不会执行的,所以你的close没有执行,请改用show or 将close 提前,令外
main:=Tmain.Create(self);令人费解
 
main:=Tmain.Create(self)用于创建main窗口对象,创建后才能使用showmodal显示。
以上方法均不能真正关闭窗口。请问还有什么办法吗?
 
建议你在打开你用以下代码
(FrmMain为主Form,form1为你要showmodal的form)
在你要show form1的时候用以下代码(在主form的菜单或按钮事件中用)

if form1=nil then
Application.createform(TFrom1,Form1)
else
begin
Form1:=Nil;
Application.createform(TFrom1,Form1);
end;

在Form1的onclose事件中用
action:=caFree;

ok了。
 
to sunny_sky;
我费解的是你的编程方式,而不是不懂main:=Tmain.Create(self);
我以为你知道在ONclose事件中加入
action=cafree;
form1:=nil;
原来你连这个还不知,那我就少说了一句,现在一定可以了
还不可以就是你没有按我们的方法好好去做
我希望告诉你怎么做,而不是写源程序给你
 
在main的OnShow中Close当前窗体.
 
main.Showmodal;
模态窗口如何真正释放呢?
用action:=caFree;么?
 
关闭后,Form1.Free;
 
onclosequery
main:=Tmain.Create(self);
main.Showmodal;
onclose
close;(切换到main窗口,同时关闭本窗口)
 
后退
顶部