例如
window w_open
open( w_open,'w_test')
语句执行后,生成一个窗口对象w_open,而不是w_test.所以不能以w_test引用
解决方法:
1.定义全局变量 window gw_openwindow[] //定义窗口数组,保存打开的窗口
string gs_windowname //类名 w_test
2.定义全局函数
none function gf_savewindow(rw_window,vs_windowname)
返回值 无
参数 rw_window 当前打开的窗口 引用
vs_windowname 打开窗口的类名 传值
int i,n
n=upperbound(gw_openwindow)
for i=1 to n
if gs_windowname[i]=vs_windowname then
gw_openwindow[i]=rw_window
return
end if
next
gw_openwindow[i]=rw_window
gs_windowname[i]=vs_windowname
int function gf_getwindow(vs_windowname)
int i,n
n=upperbound(gw_openwindow)
for i=1 to n
if gs_windowname[i]=vs_windowname and isvalid(gw_openwindow[i]) then return i
next
return -1 //窗口不存在,调用它的函数必须检查返回值,不必判断有效性
3.使用
打开时 window w_open
open( w_open,'w_test')
gf_savewindow(w_open,'w_test') //保存打开的窗口
引用时 int n
n=gf_getwindow('w_test')
if n<>-1 then
gw_openwindow[n].其它属性或函数或事件
end if
window w_open
open( w_open,'w_test')
语句执行后,生成一个窗口对象w_open,而不是w_test.所以不能以w_test引用
解决方法:
1.定义全局变量 window gw_openwindow[] //定义窗口数组,保存打开的窗口
string gs_windowname //类名 w_test
2.定义全局函数
none function gf_savewindow(rw_window,vs_windowname)
返回值 无
参数 rw_window 当前打开的窗口 引用
vs_windowname 打开窗口的类名 传值
int i,n
n=upperbound(gw_openwindow)
for i=1 to n
if gs_windowname[i]=vs_windowname then
gw_openwindow[i]=rw_window
return
end if
next
gw_openwindow[i]=rw_window
gs_windowname[i]=vs_windowname
int function gf_getwindow(vs_windowname)
int i,n
n=upperbound(gw_openwindow)
for i=1 to n
if gs_windowname[i]=vs_windowname and isvalid(gw_openwindow[i]) then return i
next
return -1 //窗口不存在,调用它的函数必须检查返回值,不必判断有效性
3.使用
打开时 window w_open
open( w_open,'w_test')
gf_savewindow(w_open,'w_test') //保存打开的窗口
引用时 int n
n=gf_getwindow('w_test')
if n<>-1 then
gw_openwindow[n].其它属性或函数或事件
end if
本文介绍了一种通过全局变量和函数管理窗口引用的方法,确保能够正确引用已打开的窗口,避免因引用错误导致的问题。该方法包括定义窗口数组保存窗口对象、定义函数保存和获取窗口引用。

被折叠的 条评论
为什么被折叠?



