十六、窗口操作函数
1、Close()
功 能:关闭窗口并释放窗口以及窗口上的控件所占据的内存。
语 法:Close(windowname)
参 数:windowname:要关闭窗口的名称。
返回值:Integer。函数执行成功时返回1,发生错误时返回-1。如果参数windowname的值为NULL,Close()函数返回NULL。
用 法:应用程序使用Open()或其它Open簇函数打开窗口后,不需要窗口时,可以使用Close()关闭窗口并释放窗口以及窗口上所有控件占据的内存。Close()函数的执行过程为:如果要关闭窗口的CloseQuery和/或Close事件已经编写了事件处理程序,那么执行这些事件处理程序,从屏幕上删除要关闭的窗口、关闭窗口、之后执行调用Close()函数语句后面的语句。
当窗口被关闭后,应用程序就不能再访问已经关闭窗口的属性、实例变量、对象函数、以及窗口上的控件了。如果关闭窗口后应用程序依然访问上述特性,那么将引发运行错误。
当然,应用程序也可以阻止窗口被关闭,方法很简单,只要在欲阻止关闭窗口的CloseQuery事件处理程序中使用RETURN语句返回1即可,格式为:RETURN 1。
示 例:These statements close the window w_employee and then open the window
w_departments:
Close(w_employee)
Open(w_departments)
After you call Close, the following statements in the script for the CloseQuery event prompt the user for confirmation and prevent the window from closing:
IF MessageBox('ExitApplication','Exit?', Question!, YesNo!) = 2 THEN
// If no, stop window from closing
RETURN 1
END IF
2、CloseWithReturn()
功 能:关闭窗口并将返回值保存在Message对象中,该函数只能对响应窗口使用。
语 法:CloseWithReturn ( windowname, returnvalue)
参 数:windowname:要关闭窗口的名称;
returnvalue:指定关闭窗口时保存到Message对象中的值,调用CloseWithReturn()函数的代码段通过查看Message对象属性的值得到关闭窗口时被关闭窗口传递的值。returnvalue参数必须是下述三种类型之一:String、Numeric、PowerObject。
返回值:Integer。函数执行成功时返回1,发生错误时返回-1。如果参数任何的值为NULL,CloseWithReturn()函数返回NULL。
示 例:This statement closes the response window w_employee_response, returning the string emp_name to the window that opened it:
CloseWithReturn(Parent, "emp_name")
Suppose that a menu item opens one window if the user is a novice and another window if the user is experienced. The menu item displays a response window called w_signon to prompt for the user's experience level. The user types an experience level in the SingleLineEdit control sle_signon_id. The OK button in the response window passes the text in sle_signon_id back to the menu item script. The menu item script checks the StringParm property of the Message object and opens the desired window.
The script for the Clicked event of the OK button in the w_signon response window is a single line:
CloseWithReturn(Parent, sle_signon_id.Text)
The script for the menu item is:
string ls_userlevel
// Open the response window
Open(w_signon)
// Check text returned in Message object
ls_userlevel = Message.StringParm
IF ls_userlevel = "Novice" THEN
Open(win_novice)
ELSE
Open(win_advanced)
END IF
3、Open()
功 能:打开窗口。该函数有两种语法格式:
语法一、打开编程时已知数据类型的窗口对象;
语法二、打开程序运行后才能确定数据类型的窗口对象。下面分别予以介绍:
语法一、打开编程时已知数据类型的窗口对象
语 法:Open ( windowvar {, parent } )
参 数:windowvar:要打开窗口的窗口名,可以使用窗口画笔定义的窗口对象名,也可以使用该窗口对象的某个变量。Open()函数把打开窗口的引用放置到windowvar变量中;
parent:可选项,指定要打开窗口的父窗口,要打开窗口成为父窗口的子窗口,只有当要打开窗口需要成为某个窗口的子窗口时才需要指定该参数。如果应用程序使用Open()函数打开某个子窗口或弹出窗口而又省略了该参数,那么当前活动窗口成为被打开窗口的父窗口。
返回值:Integer。函数执行成功时返回1,发生错误时返回-1。如果任何参数的值为NULL,Open()函数返回NULL。
示 例:This statement opens an instance of a window named w_employee:
Open(w_employee)
The following statements open an instance of a window of the type w_employee:
w_employee w_to_open
Open(w_to_open)
The following code opens an instance of a window of the type child named cw_data and makes w_employee the parent:
child cw_data
Open(cw_data, w_employee)
The following code opens two windows of type w_emp:
w_emp w_e1, w_e2
Open(w_e1)
Open(w_e2)
语法二、打开程序运行后才能确定数据类型的窗口对象
语 法:Open ( windowvar, windowtype {, parent } )
参 数:windowvar:指定窗口变量名,Open()函数把打开窗口的引用放置到该变量中windowtype:string类型,指定要打开窗口的数据类型,该参数指定的窗口数据类型必须与windowvar参数的类型相同或是windowvar类型的后继对象;
parent:可选项,指定要打开窗口的父窗口,要打开窗口成为父窗口的子窗口,只有当要打开窗口需要成为某个窗口的子窗口时才需要指定该参数。如果应用程序使用Open()函数打开某个子窗口或弹出窗口而又省略了该参数,那么当前活动窗口成为被打开窗口的父窗口。
返回值:Integer。函数执行成功时返回1,发生错误时返回-1。如果任何参数的值为NULL,Open()函数返回NULL。
示 例:This example opens a window of the type specified in the string s_w_name and stores the reference to the window in the variable w_to_open. The SELECT statement retrieves data specifying the window type from the database and stores it in s_w_name:
window w_to_open
string s_w_name
SELECT next_window INTO : s_w_name FROM routing_table
WHERE... ;
Open(w_to_open, s_w_name)
This example opens an array of ten windows of the type specified in the string is_w_emp1 and assigns a title to each window in the array. The string is_w_emp1 is an instance variable whose value is a window type:
integer n
window win_array[10]
FOR n = 1 to 10
Open(win_array[n], is_w_emp1)
win_array[n].title = "Window " + string(n)
NEXT
The following statements open four windows. The type of each window is stored in the array w_stock_type. The window reference from the Open function is assigned to elements in the array w_stock_win:
window w_stock_win[ ]
string w_stock_type[4]
w_stock_type[1] = "w_stock_wine"
w_stock_type[2] = "w_stock_scotch"
w_stock_type[3] = "w_stock_beer"
w_stock_type[4] = "w_stock_soda"
FOR n = 1 to 4
Open(w_stock_win[n], w_stock_type[n])
NEXT
4、OpenSheet()
功 能:在MDI框架窗口中打开MDI子窗口,并在指定菜单中创建选择该子窗口的菜单项。
语 法:OpenSheet(sheetrefvar{,windowtype},mdiframe{,position{,arrangeopen}})
参 数:sheetrefvar:指定要作为工作表打开的窗口名;
windowtype:string类型,可选项,指定要打开窗口的类型(也就是窗口画笔中保存的窗口对象名);
mdiframe:指定要放置工作表的MDI框架窗口名;
position:可选参数,指定所打开的工作表的名称作为一个菜单项显示在第几个菜单标题下面,缺省时,被放在倒数第二个菜单标题下,原因是,大多数商业软件的最后两个菜单标题是Window和Help,把工作表的名称放到Window菜单标题中用于选择工作表窗口是个合情合理的选择;
arrangeopen:ArrangeOpen枚举类型,可选参数,但如果选用了此参数,那么position参数也必须同时指定。arrangeopen参数告诉系统如何显示打开的工作表。
返回值:Integer。函数执行成功时返回1,发生错误时返回-1。如果参数任何的值为NULL,OpenSheet()函数返回NULL。
用 法:arrangeopen参数的可能取值为:
Cascaded! -- 把一个工作表放在另一个的上面,每个都向右下方偏移一点,这样所有工作表的标题栏用户都能看到。该值是OpenSheet()函数的缺省选择;
Layered! -- 将工作表显示在客户区的左上角,并最大化工作表,使其充满MDI框架窗口的整个客户区;
Original! -- 操作动作与Cascaded!参数相同,只是不放大窗口,而以窗口定义时的大小显示。
示 例:This statement opens the sheet child_1 in the MDI frame MDI_User in its original size. It appends the name of the opened sheet to the second menu item in the menu bar, which is now the menu associated with child_1, not the menu associated with the frame:
OpenSheet(child_1, MDI_User, 2, Original!)
This example opens an instance of the window object child_1 as an MDI sheet and stores a reference to the opened window in child. The name of the sheet is appended to the fourth menu associated with child_1 and is layered:
window child
OpenSheet(child, "child_1", MDI_User, 4, Layered!)
5、OpenSheetWithParm()
功 能:在MDI框架窗口中打开MDI子窗口,同时把参数保存在Message对象中进行传递。
语 法:OpenSheetWithParm(sheetrefvar,parameter{,windowtype},mdiframe{,position{,arrangeopen}}
参 数:sheetrefvar:指定要作为工作表打开的窗口名;
parameter:指定要传递给打开工作表的数据,该数据保存在Message对象的属性中, parameter参数的数据类型必须是下述三种类型之一:String、Numeric、PowerObjectwindowtype:string类型,可选项,指定是要打开窗口的类型(也就是窗口画笔中保存的窗口对象名);
mdiframe:指定要放置工作表的MDI框架窗口名;
position:可选参数,指定所打开的工作表的名称作为一个菜单项显示在第几个菜单标题下面,缺省时,被放在倒数第二个菜单标题下,原因是,大多数商业软件的最后两个菜单标题是Window和Help,把工作表的名称放到Window菜单标题中用于选择工作表窗口是个合情合理的选择;
arrangeopen:ArrangeOpen枚举类型,可选参数,但如果选用了此参数,那么position参数也必须同时指定。arrangeopen参数告诉系统如何显示打开的工作表。
返回值:Integer。函数执行成功时返回1,发生错误时返回-1。如果参数任何的值为NULL,OpenSheet()函数返回NULL。
用 法:arrangeopen参数的可能取值为:
Cascaded! -- 把一个工作表放在另一个的上面,每个都向右下方偏移一点,这样所有工作表的标题栏用户都能看到。该值是OpenSheet()函数的缺省选择。
Layered! -- 将工作表显示在客户区的左上角,并最大化工作表,使其充满MDI框架窗口的整个客户区。
Original! -- 操作动作与Cascaded!参数相同,只是不放大窗口,而以窗口定义时的大小显示。
示 例:This statement opens the sheet w_child_1 in the MDI frame MDI_User in its original size and stores MA in message.StringParm. It appends the names of the open sheet to the second menu item in the menu bar of MDI_User (the menu associated with w_child_1):
OpenSheetWithParm(w_child_1, "MA",MDI_User, 2, Original!)
The next example illustrates how to access parameters passed in the Message object. These statements are in the scripts for two different windows. The script for the first window declares child as a window and opens an instance of w_child_1 as an MDI sheet. The name of the sheet is appended to the fourth menu item associated with w_child_1 and is layered.
The script also passes a reference to the SingleLineEdit control sle_state as a PowerObject parameter of the Message object. The script for the Open event of w_child_1 uses the text in the edit control to determine what type of calculations to perform. Note that this would fail if sle_state no longer existed when the second script refers to it. As an alternative, you could pass the text itself, which would be stored in the String parameter of Message.
The second script determines the text in the SingleLineEdit and performs processing based on that text.
The script for the first window is:
window child
OpenSheetWithParm(child, sle_state,"w_child_1", MDI_User, 4, Layered!)
The second script, for the Open event in w_child_1, is:
SingleLineEdit sle_state
sle_state = Message.PowerObjectParm
IF sle_state.Text = "overtime" THEN
... // overtime hours calculations
ELSEIF sle_state.Text = "vacation" THEN
... // vacation processing
ELSEIF sle_state.Text = "standard" THEN
... // standard hours calculations
END IF
6、OpenWithParm()
功 能:带参数打开窗口,与打开窗口的Open()函数相似,OpenWithParm()有两种语法格式:
语法一、带参数打开编程时已知数据类型的窗口对象;
语法二、带参数打开程序运行后才能确定数据类型的窗口对象。下面分别予以介绍:
语法一、带参数打开编程时已知数据类型的窗口对象
语 法:OpenWithParm(windowvar,parameter{,parent})
参 数:windowvar:要打开窗口的窗口名,可以使用窗口画笔定义的窗口对象名,也可以使用该窗口对象的某个变量。Open()函数把打开窗口的引用放置到windowvar变量中;
parameter:指定要传递给打开窗口的数据,该数据保存在Message对象的属性中,parameter参数的数据类型必须是下述三种类型之一:String、Numeric、PowerObject;
parent:可选项,指定要打开窗口的父窗口,要打开窗口成为父窗口的子窗口,只有当要打开窗口需要成为某个窗口的子窗口时才需要指定该参数。如果应用程序使用Open()函数打开某个子窗口或弹出窗口而又省略了该参数,那么当前活动窗口成为被打开窗口的父窗口。
返回值:Integer。函数执行成功时返回1,发生错误时返回-1。如果任何参数的值为NULL,OpenWithParm()函数返回NULL。
用 法:消息对象Message有三个属性用于存储OpenWithParm()函数传递给打开窗口的数据。根据parameter参数数据类型的不同,该参数的值保存在Message对象的不同属性中。
示 例:This statement opens an instance of a window named w_employee and stores the string parameter in Message.StringParm. The script for the window's Open event uses the string parameter as the text of a StaticText control st_empname. The script that opens the window has the following statement:
OpenWithParm(w_employee, "James Newton")
The window's Open event script has the following statement:
st_empname.Text = Message.StringParm
The following statements open an instance of a window of the type w_employee. Since the parameter is a number it is stored in Message.DoubleParm:
w_employee w_to_open
integer age = 50
OpenWithParm(w_to_open, age)
The following statement opens an instance of a child window named cw_data and makes w_employee the parent. The window w_employee must already be open. The parameter benefit_plan is a string and is stored in Message.StringParm:
OpenWithParm(cw_data, "benefit_plan", w_employee)
语法二、带参数打开程序运行后才能确定数据类型的窗口对象
语 法:OpenWithParm(windowvar,parameter,windowtype{,parent})
参 数:windowvar:指定窗口变量名,Open()函数把打开窗口的引用放置到该变量中;
parameter:指定要传递给打开窗口的数据,该数据保存在Message对象的属性中,parameter参数的数据类型必须是下述三种类型之一:String、Numeric、PowerObject;
windowtype:string类型,指定要打开窗口的数据类型,该参数指定的窗口数据类型必须与windowvar参数的类型相同或是windowvar类型的后继对象;
parent:可选项,指定要打开窗口的父窗口,要打开窗口成为父窗口的子窗口,只有当要打开窗口需要成为某个窗口的子窗口时才需要指定该参数。如果应用程序使用Open()函数打开某个子窗口或弹出窗口而又省略了该参数,那么当前活动窗口成为被打开窗口的父窗口。
返回值:Integer。函数执行成功时返回1,发生错误时返回-1。如果任何参数的值为NULL,OpenWithParm()函数返回NULL。
示 例:These statements open a window of the type specified in the string s_w_name and store the reference to the window in the variable w_to_open. The script gets the value of s_w_name, the type of window to open, from the database. The parameter in e_location is text, so it is stored in Message.StringParm:
window w_to_open
string s_w_name, e_location
e_location = sle_location.Text
SELECT next_window INTO :s_w_name
FROM routing_table
WHERE ... ;
OpenWithParm(w_to_open, e_location, s_w_name)
The following statements open a window of the type specified in the string c_w_name, store the reference to the window in the variable wc_to_open, and make w_emp the parent window of wc_to_open. The parameter is numeric, so it is stored in Message.DoubleParm:
window wc_to_open
string c_w_name
integer age = 60
c_w_name = "w_c_emp1"
OpenWithParm(wc_to_open, age, c_w_name, w_emp)