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:
|
1 |
integer li_data |
|
1 |
FOR li_cnt = 1 to 100 |
|
1 |
li_data = dw_1.Object.emp_salary[li_cnt] |
|
1 |
.. // Code to process data value |
|
1 |
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:
|
1 |
integer li_data |
|
1 |
DWObject dwo_empsalary |
|
1 |
|
1 |
dwo_empsalary = dw_1.Object.emp_salary |
|
1 |
|
1 |
FOR li_cnt = 1 to 100 |
|
1 |
li_data = dwo_empsalary.Primary[li_cnt] |
|
1 |
.. // Code to process data value |
|
1 |
NEXT |
PowerBuilder 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:
|
1 |
dw_1.Object.emp_salary[1] //Single data item |
|
1 |
|
1 |
DWObject dwo_empsalary |
|
1 |
dwo_empsalary = dw_1.Object.emp_salary |
|
1 |
dwo_empsalary[1] // Incorrect: array of DWObject |
|
1 |
dwo_empsalary.Primary[1] // Single data item |