不重复创建子窗体

xuxugr 2009-06-07 10:50:47
if not IsWindowExists('frm_spbm') then
Application.CreateForm(Tfrm_spbm,frm_spbm);
frm_spbm.show;


function IsWindowExists(form_1:string):boolean ;
var com_count,i:integer;
begin
com_count:=strtoint((inttostr(Application.ComponentCount)))-1;
for i:=0 to com_count do
begin
if Application.Components[i].Name=form_1 then
break;
end;
if i > com_count then
result:=false
else
result:=true;
end;

这样不行


if not assigned(frm_spbm) then
Application.CreateForm(Tfrm_spbm,frm_spbm);
frm_spbm.show;
这样也不行,还是重复创建了,怎么回事
...全文
100 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bruce20062006 2009-06-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 taxi 的回复:]
窗体关闭的时候不是销毁,只是不可见吧。
在OnClose中,将Action 设为 caFree,同时将frm_spbm 设为 nil应该可以了吧。
然后就可以用if Assinged(frm_spbm)进行判断了。
[/Quote]


我的意思是我的窗体没有关加呀,也就是希望如果同样的窗体打开了就不需要再打开了,我都没关,应该是打开窗体时判断一下,if Assinged(frm_spbm)我也加了,没用
bruce20062006 2009-06-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 delphi_911 的回复:]
MDI中子窗体的OnClose中加上一句才能释放:

Delphi(Pascal) code
Action:=caFree;
[/Quote]


我加了

在OnClose中,将Action 设为 caFree,同时将frm_spbm 设为 nil应该可以了吧。

nil我没加
delphi_911 2009-06-07
  • 打赏
  • 举报
回复
MDI中子窗体的OnClose中加上一句才能释放:

Action:=caFree;
taxi 2009-06-07
  • 打赏
  • 举报
回复
窗体关闭的时候不是销毁,只是不可见吧。
在OnClose中,将Action 设为 caFree,同时将frm_spbm 设为 nil应该可以了吧。
然后就可以用if Assinged(frm_spbm)进行判断了。
taxi 2009-06-07
  • 打赏
  • 举报
回复
//这样也不行?
if not assigned(frm_spbm) then
frm_spbm := Tfrm_spbm.Create(Self);
frm_spbm.Show;

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧