The example below is to explain how to use Structure in Powerbuilder
Let say, you need to passing 4 parameters which have 3 different data types: string, datetime and decimal, when you open a new window.
First, you need to create a new Structure. At the main painter, click Structure button.
Click New to create a new structure
Fill the variables that you want to pass. You can set the different type for each variables.
Save by clicking Save button (of Choose menu File than Save). Type str_dailydiscountreport as a name. str_ is a prefix to represent that the object is a Structure.
In the script that will open the new window, type following code. This code is to declare the new structure variable which pointed to str_dailydiscountreport structure that we have build in the first.
1: // declare new structure variable
2: str_dailydiscountreport strReport
3:
4: // fill each variable in the structure
5: strReport.sProductCode = sle_productcode.text
6: strReport.dtDateFrom = datetime(em_datefrom.text)
7: strReport.dtDateUntil = datetime(em_datefrom.text)
8: strReport.dDiscount = Dec(em_discount.text)
9:
10: // Open the new window with passing the structure
11: OpenWithParm(w_report,strReport)
How to received?
In event Open of the w_report window, do same with the script above.
1: // declare new structure variable
2: str_dailydiscountreport strReport
3:
4: // receive the structure that passed from the window caller by using message object with PowerobjectParm as property
5: strReport = message.PowerobjectParm
6:
7: // extract all the variables inside the structure
8: MessageBox("Product Code",strReport.sProductCode)
9: MessageBox("Date From",Str(strReport.dtDateFrom,'dd/mm/yyyy')
10: MessageBox("Date Until",Str(strReport.stDateUntil,'dd/mm/yyyy')
11: MessageBox("Discount",Str(strReport.dDiscount,'##.##') + "%"
No comments:
Post a Comment