动态将其他窗体关闭(100分)

  • 主题发起人 主题发起人 yjpya
  • 开始时间 开始时间
Y

yjpya

Unregistered / Unconfirmed
GUEST, unregistred user!
各位朋友:
  小弟的程序全部窗体都是采用“窗体.SHOW”的形式,现想向大家请教一段代码,就是每一个窗体在SHOW的时候,都将其他已经SHOW了的窗体关闭,但主窗体不用关闭。即在主窗体里,每次只能SHOW一个窗体,在主窗体里SHOW另外一个窗体的时候,会将前一个已经SHOW了的窗体关闭,请问该怎样写这段代码,请各位朋友赐教,多谢!!!
 
1.知道其他的已经打开的窗口,一一关闭就可以了!
2.不知道已经打开的窗口.
var
i:Integer;
begin
for i:=0 to Application.ComponentCount-1 do
begin
if (Application.Components is TForm) then
begin
if (Application.MainForm <>(Application.Components)) then
(Tform(Application.Components)).Close;
end;
//show 你想 show 的窗体
end;
 
上面的朋友,谢了,我试试,但好像应该改为如下才对 :)
var
i:Integer;
begin
for i:=0 to Application.ComponentCount-1 do
begin
if (Application.Components is TForm) then
begin
if (Application.MainForm <>(Application.Components)) then
(Tform(Application.Components)).Close;
end;
end;
//show 你想 show 的窗体
 
to yjpya:
这段程序应该放在窗口显示命令之前,先判断是否有窗口打开,有则关闭,然后再打开相要打开的窗口。具体应该如下:
var
i:Integer;
begin
for i:=0 to Application.ComponentCount-1 do
begin
if (Application.Components is TForm) then
begin
if (Application.MainForm <>(Application.Components)) then
(Tform(Application.Components)).Close;
end;
end;
目标窗体.show;
end;←不能少。
 
每个窗体都用模式显示不就可以了?
 
(Application.MainForm <>(Application.Components)) then
(Tform(Application.Components)).Close;
end;
end;
目标窗体.create(nil)
目标窗体.show;
end;←不能少。
 
这个问题很简单,和我的程序是一样的功能。
功能就是注销对吧。
技术交流QQ:136293586
 
呵呵!对,这个show是后加的,位置加错了!!
 
不是吧?路过!
 
不难,一一关闭就可以了
 
起他窗体hint就可以了
 
要我用的话我会用WM_CLOSE,窗口打开的时候把句柄记下,打开一个子窗体就请求主程序关掉已经打开过的其他窗体,如果存在的话。
 
为什么不showmodal呢?
 
多人接受答案了。
 
后退
顶部