Transfer multiple parameters between PB windows
Shenzhen:-11-24
Function openwithparm, closewithreturn, opensheetwithparm, windowname. openuserobjectwithparm in PowerBuilder
There is a parameter or returnvalue that is saved to the message object during window operations (open or close.
The message object has three attributes used to store the data that these functions pass to the window (depending on the type specified by parameters during window operations ).
The parameter value is stored in different attributes of the message object according to the Data Type of the parameter/returnvalue parameter.
The relationship between the parameter/returnvalue type and the message object attribute used is as follows:
Parameter type message object attributes
Numeric (numeric) message. doubleparm
Powerobject (PB object, including user-defined structure data type) message. powerobjectparm
String (string) message. stringparm
Based on the parameter/returnvalue parameter type of functions such as openwithparm (), the application extracts this function from different attributes of the message object and transmits it
The value of the window to be opened.
If a parameter is passed in Pb, it is easy to implement. In the call script, you can use the following code:
Openwithparm (W_1, "dedicated for defeat ")
In the W_1 open event window, type:
Sle_1.text = message. stringparm
To pass multiple parameters, you can use the following two methods:
Method 1
Define the structure variable: lstr_para, which contains the parameters you want to pass:
Variable name variable type
Id string
Name string
Sex string
Loca string
In the call script (in this example, click ed), use the following code:
Lstr_para lstr_tranpara
Lstr_tranparta.id = "00000001"
Lstr_tranpara.name = "dedicated for defeat"
Lstr_tranpara.sex = "male"
Lstr_tranpara.loca = "Guangdong and Shenzhen"
Openwithparm (W_2, lstr_tranpara)
Next, in the W_2 open event window, obtain the structure information:
Lstr_para lstr_getpara
Lstr_getpara = message. powerobjectparm
Sle_1.text = lstr_getpara.id
Sle_2.text = lstr_getpara.name
Sle_3.text = lstr_getpara.sex
Sle_4.text = lstr_getpara.loca
Here, lstr_getpara is the data type of the user-defined structure, which is transmitted by value.
Method 2
First, create a class user object
Uo_para
In this user object, declare the parameters you need to pass into instance variables, for example:
Public:
String ID
String name
String sex
String loca
In the call script (in this example, click ed), use the following code:
Uo_para uo_tranpara
Uo_tranpara = create uo_para
Uos_tranpara.id = "00000001"
Uo_tranpara.name = "dedicated for defeat"
Uo_tranpara.sex = "male"
Uo_tranpara.loca = "Guangdong and Shenzhen"
Openwithparm (w_3, uo_tranpara)
Next, in the w_3 open event window, obtain the user object information:
Uo_para uo_getpara
Uo_getpara = message. powerobjectparm
Sle_1.text = uo_getpara.id
Sle_2.text = uo_getpara.name
Sle_3.text = uo_getpara.sex
Sle_4.text = uo_getpara.loca
Compared with the above two methods, although the first method is relatively simple and practical, it cannot be fully described in a structure data if complicated data is encountered;
The second method is not only convenient and flexible, but also can transmit complex data. Of course, you can use global variables or public
The accessed window instance variables are used to transmit parameters, or call a function in the window and pass the required parameters.
In addition, you must pay attention to the following points when passing parameters using message:
1. It is best to pass the value of the message object to the variable immediately after the window operation (open or close) is completed, because the message is a global object,
Each event is used when it is triggered or transmitted. Other Scripts may also use message objects, so it may be overwritten.
2. Avoid sending null objects to avoid program errors.