Method of passing multiple parameters between PB windows
Shenzhen: Lonely for 2003-11-24
The function openwithparm,closewithreturn,opensheetwithparm,windowname in PowerBuilder. Openuserobjectwithparm
There is a parameter parameter or returnvalue that is stored in the Message object when the window operation (open or close) is performed.
Message object messages have three properties that store the data that these functions pass to the window (depending on the type that the parameter is assigned to when the window is manipulated).
Depending on the data type of the Parameter/returnvalue parameter, the value of the parameter is saved in different properties of the message object.
The corresponding relationship between the type of the Parameter/returnvalue parameter and the Message object property used is the following table:
Parameter type Message object property
Numeric (value) message.doubleparm
Powerobject (PB objects, including user-defined structure data types) Message.powerobjectparm
String (String) message.stringparm
The application extracts the function from different properties of the message messages object according to the Parameter/returnvalue parameter type of the function such as Openwithparm () and transmits
Gives the value of the window being opened.
It is easy to implement a parameter in PB if it is passed. In the call script, you can use the following code:
Openwithparm (W_1, "alone to find defeat")
Then, in the Open event that opens the window w_1, type:
Sle_1.text = Message.stringparm
If you need to pass multiple parameters, you can use the following two methods:
Method One
Define the structure variable: Lstr_para, which contains the various parameters you want to pass:
Variable name variable type
ID string
Name string
Sex string
Loca string
In the call script (in this case, the menu clicked), use the following code:
Lstr_para Lstr_tranpara
Lstr_tranpara.id = "00000001"
Lstr_tranpara.name = "Alone to find a defeat"
Lstr_tranpara.sex = "Male"
Lstr_tranpara.loca = "Shenzhen, Guangdong"
Openwithparm (W_2,lstr_tranpara)
Next, in the Open event that opens the window w_2, get 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
Where Lstr_getpara is the user-defined structure data type, is the value of the transfer.
Method Two
First create a class user object
Uo_para
Declare the various parameters you need to pass as instance variables in the user object, for example:
Public
String ID
String name
String sex
String Loca
In the call script (in this case, the menu clicked), use the following code:
Uo_para Uo_tranpara
Uo_tranpara = Create Uo_para
Uo_tranpara.id = "00000001"
Uo_tranpara.name = "Alone to find a defeat"
Uo_tranpara.sex = "Male"
Uo_tranpara.loca = "Shenzhen, Guangdong"
Openwithparm (W_3,uo_tranpara)
Next, in the Open event that opens the window w_3, get 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, the first method is relatively simple and practical, but if it encounters more complex data, it can not be fully described in a structure data;
The second method is not only convenient and flexible, but also can transmit complex data. Of course, there are several ways to transfer parameters, and you can use global variables or public
Access the window instance variable to pass the parameter, or call a function in the window, and pass the required parameters, here is no longer to repeat.
In addition, you must note the following points when passing parameters with message:
1. It is best to pass the value of the message object to the variable immediately after the window operation (on or off), because the message is a globally used object.
Each time an event is triggered or transmitted, it is used, and other script may use the Message object, so it is in danger of being overwritten.
2. Avoid sending null objects to avoid program errors.