DWObject variables in PowerBuilder

In PowerBuilder, you can get better performance by using a DWObject variable to resolve the object reference in a DataWindow property or data expression. Evaluating the reference once and reusing the resolved reference is more efficient than fully specifying the object reference again.

This technique yields the most benefit if your application uses compiled code or if you are using a DataWindow expression in a loop.

For example, this code is not optimized for best performance, because the fully specified data expression within the loop must be resolved during each pass:

integer li_data

FOR li_cnt = 1 to 100

		li_data = dw_1.Object.emp_salary[li_cnt]

		.. // Code to process data value

NEXT

This code has been optimized. The reference to the control within the DataWindow (emp_salary) is resolved once before the loop begins. The reference stored in the DWObject variable is reused repeatedly in the loop:

integer li_data

DWObject dwo_empsalary


dwo_empsalary = dw_1.Object.emp_salary


FOR li_cnt = 1 to 100

		li_data = dwo_empsalary.Primary[li_cnt]

		.. // Code to process data value

NEXT

NotePowerBuilder DWObject versus data In a data expression for a column that refers to one item, the brackets for the row index identify the expression as a data expression (for information, see “Syntax for one or all data items in a named column”). However, if you assign the column control to a DWObject variable, the brackets incorrectly signify an array of objects. Therefore you must include a buffer name or data source to specify that you want data:

dw_1.Object.emp_salary[1] //Single data item


DWObject dwo_empsalary

dwo_empsalary = dw_1.Object.emp_salary

dwo_empsalary[1] // Incorrect: array of DWObject

dwo_empsalary.Primary[1] // Single data item