Mastering PowerBuilder

HomePrevious Lesson: Describe & Modify Functions
Next Lesson: Treeview Control

New Dot Notation Syntax For DataWindow Objects

With version 5.0, Powersoft introduced a new syntax for accessing the DataWindow object in a DataWindow control or DataStore. That's .Object notation. Using this convention, you reduce a lot of Describe and Modify() calls. In some cases where you add records in a loop and set each item, you can see a lot of performance improvement with this syntax. You can also reduce a lot of code.

Using this new syntax, you can do two things. One is reading/changing the data and another is reading/changing the elements attributes.

We use ".Object" syntax for data manipulation. The syntax is available in different flavors.
dw_product.Object.Data[ 1, 2 ] = "obsolete "+ &
dw_product.Object.Data[ 1, 2 ]

In the above example we are making a product obsolete by prefixing "obsolete" to the product_description. In the Data[1,2], 1 is the row number and 2 is the column number. In this convention, we need to use .Object literally after the DataWindow control name. The full syntax is:
dwcontrol.Object.Data {.buffer } {.datasource } &
[ rownum, colnum ]

Buffer and DataSource are optional. Primary is the default for buffer and current is the default for DataSource. In the above example, we are basically changing a specific column in a specific row. If you want to change few columns in a few rows, we have a different syntax:
dwcontrol.Object.Data {.buffer } {.datasource } &
[ startrownum, startcolnum, endrownum, endcolnum ]

If you want to change the whole row, the following is the syntax:
dwcontrol.Object.Data {.buffer } {.datasource } &
{[ rownum ]}

This syntax is useful when you want to set the whole row. If you want to set all rows, don't specify the row number. This syntax is useful when you have the data in an array and want to load the data from the array into a DataWindow. If you want to change all the selected rows, use the following syntax:
dwcontrol.Object.Data {.Primary } {.datasource } .Selected

Please note the word , .Primary after the .Data in this syntax, in other syntaxes you have the choice of specifying the buffer.

when you know the field name, you can use the following syntax for multiple rows:
dwcontrol.Object.columnname{.buffer}{.datasource} &
[startrowNo,endrowNo]

Use the following syntax to read/change a particular column in the selected rows:
dwcontrol.Object.ColName {.Primary }{.datasource}.Selected

All the above syntaxes are used to read or manipulate the data. Now, let's see changing the attributes.

Now, let's see manipulating the object attributes. The following is the syntax:
dwcontrol.Object.dwobjectname {.Object.dwobjectname}.property &
		{.property}{=value}

With this syntax, we can do everything that we can do with the Modify() function. The following makes the DataWindow read-only:
dw_employee.Object.DataWindow.ReadOnly = "yes"

Previously, we have used Modify() function to make work_or_vac_code as read-only for existing rows, but editable for new rows. The following does the same thing with new syntax:
dw_emp_vacations.Object.work_or_vac_code.Protect = &
"1~tIf(IsRowNew(),0,1)"

You can observe that there is no difference in the expression.
HomePrevious Lesson: Describe & Modify Functions
Next Lesson: Treeview Control