怎么在代码中判断某个FORM已经LOAD过???

CriedSky 2003-09-10 05:44:01
如题,谢谢
...全文
54 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
Random 2003-09-11
  • 打赏
  • 举报
回复
Is Nothing 和Load是两个不同的概念,是否Is Nothing表示对象有没有实例化,有没有把一个具体的对象实例赋给变量;而是否Load则是针对一个已经实例化的窗口的状态(是否已加载),没有实例化的窗口是不能Load的!
VB中我们通常用的窗口的名字都是与窗口的类名一样,是自动实例化了的,所以是Not Is Nothing的,但未必Load过,而如果我们这样定义一个窗口:
Dim frm As Form2
在执行 Set frm=New Form2操作之前,frm Is Nothing,
如果这时执行 Load frm 就是错误的。

Set frm=Nothing 操作会使frm内的模块级变量和frm上的所有控件初始化!

而Unload frm操作只是初始化窗口中的控件!而窗口内定义的模块级的变量的值是保持不变的!
meteorkin 2003-09-11
  • 打赏
  • 举报
回复
这样不就好了嘛
加一个模块级的Bool变量
dim IsOpen as boolean
在Form_init事件中加入
isopen=true
在Form_销毁事件中
isopen=False
这就可以判断是否已经打开
为每一个窗体都创建一个就行了
viena 2003-09-11
  • 打赏
  • 举报
回复
//那是因为它已经loaded了
错误!不管有没有load,is nothing永远都是false,只要有这个Form存在

试一下,两个Form,form1,form2
只有form1中有代码,form1为启动窗体

Private Sub Form_Load()
If Not Form2 Is Nothing Then MsgBox "form2 not load,but not is nothing"
End Sub
yijiansong 2003-09-11
  • 打赏
  • 举报
回复
学习
strongfisher 2003-09-11
  • 打赏
  • 举报
回复
是啊
那是因为它已经loaded了
vv1vv 2003-09-11
  • 打赏
  • 举报
回复
If frmAbout is Nothing Then
msgbox "未加载"
Else
msgbox "已加载"
Then
xhzhang6 2003-09-11
  • 打赏
  • 举报
回复

strongfisher(Haiwolf) 的方法也是不行的
永远是
MsgBox frmCurr.name&" is loaded"
xhzhang6 2003-09-11
  • 打赏
  • 举报
回复
viena(晓琴) :
别客气,错误难免

再举个例子
Private Sub Command1_Click()
Dim f2 As Form2
If f2 Is Nothing Then 'f2对象就是Nothing
...
End If
End Sub


Private Sub Command1_Click()
Dim f2 As new Form2
If f2 Is Nothing Then 'f2对象就不是Nothing了
...
End If
End Sub

但上面两者都没有Load进来
viena 2003-09-11
  • 打赏
  • 举报
回复
赞成用全局变量(标志),想起来了,我以前有过这样的问题,用全局变量的
viena 2003-09-11
  • 打赏
  • 举报
回复
惭愧!多谢xhzhang6(zxh)指正们的错误
道素 2003-09-11
  • 打赏
  • 举报
回复
楼主的意思我还有一点不明白,load过,加载过有unload算不算load过
如果这样你一个全局变量(标志)也可以
strongfisher 2003-09-11
  • 打赏
  • 举报
回复
Dim frmCurr As Form
For Each frmCurr In Forms

If frmCurr Is Nothing Then
MsgBox frmCurr.name &" is unload"
Else
MsgBox frmCurr.name&" is loaded"
End If

Next frmCurr
CriedSky 2003-09-11
  • 打赏
  • 举报
回复
谢谢各位~~~~~~~~~~~
xhzhang6 2003-09-10
  • 打赏
  • 举报
回复



补充一下:
If IsFrmLoaded("form2") Then
MsgBox "form2 is loaded"
Else
MsgBox "form2 is unloaded"
End If



viena(晓琴) 和 liul17(liul) 所说的方法根本就是不行的!!!!!

实践检验真理!


xhzhang6 2003-09-10
  • 打赏
  • 举报
回复

Function IsFrmLoaded(ByVal strfrmName As String) As Boolean
Dim f As Form
For Each f In Forms
If f.Name = strfrmName Then
IsFrmLoaded = True
Exit Function
End If
Next
IsFrmLoaded = False
End Function
liul17 2003-09-10
  • 打赏
  • 举报
回复
新建2个窗体在form2中粘入下面代码

Private Sub Command1_Click()
If Form1 Is Nothing Then
MsgBox "form1 is unload"
Else
MsgBox "form1 is loaded"
End If
End Sub
lwm1977 2003-09-10
  • 打赏
  • 举报
回复
赘述一个Nothing吧
viena 2003-09-10
  • 打赏
  • 举报
回复
If Not Form1 Is Nothing Then MsgBox "already load"
lilaclone 2003-09-10
  • 打赏
  • 举报
回复
If frmAbout is Nothing Then
msgbox "未加载"
Else
msgbox "已加载"
Then
lilaclone 2003-09-10
  • 打赏
  • 举报
回复
判断其Is Nothing属性,如为True则表示已Load

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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