Creating a DataWindow object
This section describes how to create a DataWindow object by
calling the Create method in an application.
You should use the techniques described here for creating
a DataWindow from syntax only if you cannot accomplish what you
need to in the DataWindow painter. The usual way of creating DataWindow
objects is to use the DataWindow painter.
To learn about creating DataWindow objects
in the DataWindow painter, see the PowerBuilder Users
You use the Create method to create a DataWindow object dynamically
during execution. Create generates a DataWindow object using source
code that you specify. It replaces the DataWindow object currently
in the specified DataWindow control with the new DataWindow object.
The Create method destroys the association between the DataWindow
control and the transaction object. As a result, you need to reset
the control’s transaction object by calling the SetTransObject
or SetTrans method after you call Create.
If you used a connection technique that did not require you
to call the SetTransObject or SetTrans method, you do not need to
call it after Create either.
To learn how to associate a DataWindow control
with a transaction object, see Chapter 2, “Using DataWindow Objects.”
Specifying the DataWindow
There are several ways to specify or generate the syntax required
for the Create method. Not all the techniques are available in all
In PowerBuilder, you can:
the SyntaxFromSQL method of the transaction object
Use the LibraryExport PowerScript function
In all environments, you can:
DataWindow.Syntax property of the DataWindow object
Create the syntax yourself
You are likely to use SyntaxFromSQL to create the syntax for
most dynamic DataWindow objects. If you use SyntaxFromSQL, all you
have to do is provide the SELECT statement and the presentation
In PowerBuilder, SyntaxFromSQL is a method of the transaction
object. The transaction object must be connected when you call the
In PowerBuilder, table names are automatically qualified with
the owner’s name if you are using a native driver. To obtain
the same results in an application, you must set the USERID property
in the transaction object so that the table name is properly qualified
and extended attributes can be looked up.
SyntaxFromSQL has three required arguments:
A string containing the SELECT statement for the DataWindow
A string identifying the presentation style and
The name of a string you want to fill with any error
messages that might result
SyntaxFromSQL returns the complete syntax for a DataWindow
object that is built using the specified SELECT statement.
If your DBMS is Adaptive Server Enterprise and you call SyntaxFromSQL, PowerBuilder
must determine whether the tables are updatable through a unique
index. This is possible only if you set AutoCommit to TRUE before calling
SyntaxFromSQL, as shown below:
sqlca.syntaxfromsql (sqlstmt, presentation, err)
Using LibraryExport in PowerBuilder
You can use the LibraryExport PowerScript function to export
the syntax for a DataWindow object and store the syntax in a string.
You can then use the exported syntax (or a modification of
the syntax) in Create to create a DataWindow object.
Using the DataWindow.Syntax property
You can obtain the source code of an existing DataWindow object
to use as a model or for making minor changes to the syntax. Many
values in the source code syntax correspond to properties of the
object in the DataWindow control, dw_1, and displays it
in the text box control, textb_dw_syntax :
dwSyntax = dw_1.<span>Describe</span>("datawindow.syntax");<br>textb_dw_syntax.value = dwSyntax;
Creating the syntax yourself
You need to create the syntax yourself to use some of the
advanced dynamic DataWindow features, such as creating a group break.
The DataWindow source code syntax that you need to supply
to the Create method can be very complex. To see examples of DataWindow
object syntax, go to the Library painter and export a DataWindow
object to a text file, then view the file in a text editor.
For more information on Create and Describe
methods as well as DataWindow object properties and syntax, see
the DataWindow Reference.