Datawindow Programmers Guide v2021
Datawindow Programmers Guide v2021
• A DataWindow object
The DataWindow object defines the data source and presentation style for the data.
Page 5
DataWindow and DataStore basics
You define DataWindow objects in the PowerBuilder DataWindow painter. You can also
define nonupdatable DataWindow objects in the InfoMaker Report painter.
For examples of the presentation styles, see Section 18.2, “Choosing a presentation style” in
Users Guide.
Data sources
The data source specifies where the data in the DataWindow comes from and what data items
are displayed. Data can come from tables in a database, a Web service, a file with data that
you can import, or code that specifies the data. For databases, the data specification is saved
in a SQL statement. In all cases, the DataWindow object saves the names of the data items to
display, as well as their datatypes.
Page 6
DataWindow and DataStore basics
• Client/server
A program running on a client workstation accesses a database running on a server. The
user interface and business logic reside together on the client computer.
Page 7
DataWindow and DataStore basics
• Distributed application
The user interface on the client computer calls components on a middle-tier server, which
execute business logic and access the database server.
• Web application
A client Web browser sends requests for HTML or JSP documents to a Web server. The
Web server passes control to a page or application server, where server-side scripts can
access components on a transaction server that can connect to databases on a database
server.
• The Window or User Object painters to add DataWindow controls to windows or visual
user objects. The DataWindow control is on the drop-down palette of controls for these
painters.
In the Window or User Object painters, you can write scripts that control the DataWindow's
behavior and manipulate the data it retrieves. Your scripts can also instantiate DataStore
objects.
Page 8
DataWindow and DataStore basics
In the PowerBuilder Browser you can examine the properties, events, and methods of
DataWindow controls and DataStore objects on the System tab page. If you have a library
open that contains DataWindow objects, you can examine the internal properties of the
DataWindow object on the Browser's DataWindow tab page.
DataWindow objects
The DataWindow control or DataStore object uses a DataWindow object defined with any
presentation style. The DataWindow object determines what data is retrieved and how it
is displayed. The control can also display Powersoft reports (PSRs), which do not need to
retrieve data.
Database connections
The PowerBuilder DataWindow can use ODBC, JDBC, and native database drivers for
database connectivity. Users can connect to a data source on any server to which they have
access, including databases and middle-tier servers on the Internet.
To make a connection, you can use the internal Transaction object of the DataWindow, or
you can make the connection with a separate PowerBuilder transaction object.
A PowerBuilder application provides a default Transaction object, SQLCA. You can define
additional Transaction objects if you need to make additional connections. When you connect
with a separate Transaction object, you can control when SQL COMMIT and ROLLBACK
statements occur, and you can use the same connection for multiple controls.
For more information about using a Transaction object with a DataWindow, see Using
DataWindow Objects.
For more information about PowerBuilder Transaction objects, see Section 4.1, “Using
Transaction Objects” in Application Techniques.
Coding
You write scripts in the Window or User Object painter to connect to the database, retrieve
data, process user input, and update data.
In PowerBuilder, you can take advantage of object inheritance by defining a user object
inherited from a DataWindow control and adding your own custom functionality. You can
reuse the customized DataWindow control throughout your applications.
You create DataStore objects, the nonvisual version of a DataWindow control, by creating
them in a script and calling methods for the object. You can also define a user object that
is inherited from a DataStore and customize it. For more information, see Using DataStore
Objects.
Libraries and applications
You store DataWindow objects in PowerBuilder libraries (PBLs) during development. When
you build your application, you can include the DataWindow objects in the application
executable or in PowerBuilder dynamic libraries (PBDs).
For more information about designing DataWindow objects and building a PowerBuilder
application, see Chapter 18, Defining DataWindow Objects in Users Guide and Part I,
“Application Techniques”.
Page 9
DataWindow and DataStore basics
Page 10
DataWindow and DataStore basics
You also use DataWindow objects in the nonvisual DataStore and in child DataWindows,
such as drop-down DataWindows and composite presentation styles. For more information
about DataStores, see Using DataWindow Objects. For more information about drop-down
DataWindows and composite DataWindows, see Part VI, “Working with DataWindows” in
Users Guide.
To use the DataWindow object in an application, you add a DataWindow control to a
window or form, then associate that control with the DataWindow object, as illustrated in the
following figure:
Figure 2-1: Putting a DataWindow object into a DataWindow control
• Procedures for inserting a control and assigning a DataWindow object to the control
Page 11
DataWindow and DataStore basics
4. (Optional) Resize the DataWindow control by selecting it and dragging one of the
handles.
Page 12
DataWindow and DataStore basics
1. In the DataWindow Properties view, click the Browse button for the DataObject
property.
2. Select the DataWindow object that you want to place in the control and click OK.
The name of the DataWindow object displays in the DataObject box in the DataWindow
Properties view.
Page 13
DataWindow and DataStore basics
For more information, see Setting the transaction object for the DataWindow control.
Dynamically creating a DataWindow object
You can also create a new DataWindow object during execution and associate it with a
control.
For more information, see Dynamically Changing DataWindow Objects.
The DataWindow object d_emp_hist was created in the DataWindow painter and stored in a
library on the application search path. The control dw_emp is contained in the window and is
saved as part of the window definition.
Preventing redrawing
You can use the SetRedraw method to turn off redrawing in order to avoid flicker and
reduce redrawing time when you are making several changes to the properties of an
object or control. Dynamically changing the DataWindow object at execution time
implicitly turns redrawing on. To turn redrawing off again, call the SetRedraw method
every time you change the DataWindow object:
dw_emp.DataObject = "d_emp_hist"
dw_emp.SetRedraw(FALSE)
Page 14
DataWindow and DataStore basics
This section provides instructions for setting the transaction object for a DataWindow control
and for using the DataWindow object to retrieve and update data.
To learn more about setting values for the transaction object, connecting to the database, and
disconnecting from the database, see:
• PowerBuilder
Section 4.1, “Using Transaction Objects” in Application Techniques.
The two methods provide different levels of control over database transactions.
Page 15
DataWindow and DataStore basics
When to use it
If the number of available connections at your site is limited, you might want to use internal
transaction management because connections are not held open.
Internal transaction management is appropriate in simple situations when you are doing pure
retrievals (such as in reporting) and do not need to hold database locks -- when application
control over committing or rolling back transactions is not an issue.
How it works
PowerBuilder
To use internal transaction management, you specify connection values for a transaction
object, which could be the automatically instantiated SQLCA. Then you call the SetTrans
method, which copies the values from a specified transaction object to the DataWindow
control's internal transaction object.
SQLCA.DBMS = ProfileString("myapp.ini", &
"database", "DBMS", " ")
... // Set more connection parameters
dw_employee.SetTrans(SQLCA)
dw_employee.Retrieve( )
For more information about PowerBuilder transaction objects, see Section 4.1, “Using
Transaction Objects” in Application Techniques.
Page 16
DataWindow and DataStore basics
Retrieve or Update
Commit or Rollback
Disconnect
In PowerBuilder, you use embedded SQL for connecting and committing.
The transaction object also stores error messages returned from the database in its properties.
You can use the error information to determine whether to commit or roll back database
changes.
When to use it
When the DataWindow control uses a separate transaction object, you have more control of
the database processing and are responsible for managing the database transaction.
There are several reasons to use a separate transaction object:
• You have several DataWindow controls that connect to the same database and you want to
make one database connection for all of them, saving the overhead of multiple connections
• You require the improved performance provided by keeping database connections open
How it works
PowerBuilder
The SetTransObject method associates a transaction object with the DataWindow control.
PowerBuilder has a default transaction object called SQLCA that is automatically
instantiated. You can set its connection properties, connect, and assign it to the DataWindow
control.
The following statement uses SetTransObject to associate the DataWindow control dw_emp
with the default transaction object (SQLCA):
// Set connection parameters in the transaction object
SQLCA.DBMS = ...
SQLCA.database = ...
CONNECT USING SQLCA;
dw_emp.SetTransObject(SQLCA)
dw_emp.Retrieve( )
Instead of or in addition to using the predefined SQLCA transaction object, you can define
your own transaction object in a script. This is necessary if your application needs to connect
to more than one database at the same time.
The following statement uses SetTransObject to associate dw_customer with a programmer-
created transaction object (trans_customer):
transaction trans_customer
trans_customer = CREATE transaction
// Set connection parameters in the transaction object
trans_customer.DBMS = ...
trans_customer.database = ...
CONNECT USING trans_customer;
dw_customer.SetTransObject(trans_customer)
dw_customer.Retrieve( )
Page 17
DataWindow and DataStore basics
• PowerBuilder
See Section 4.1, “Using Transaction Objects” in Application Techniques
For more information about SetTrans and SetTransObject methods, see Section 9.196,
“SetTrans” in DataWindow Reference and Section 9.197, “SetTransObject” in DataWindow
Reference.
When you call the Retrieve method, you supply a value for Salary. In PowerBuilder, the code
looks like this:
dw_emp.Retrieve( 50000 )
Page 18
DataWindow and DataStore basics
Update sends to the database all inserts, changes, and deletions made in the DataWindow
control since the last Update method. When you are using an external transaction object,
you can then commit (or roll back) those database updates. In PowerBuilder, you use SQL
statements.
For more specifics on how a DataWindow control updates the database (that is, which SQL
statements are sent in which situations), see Updating the database.
Examples
The following example shows code that connects, retrieves, updates, commits or rolls back,
and disconnects from the database.
Although the example shows all database operations in a single script or function, most
applications separate these operations. In a PowerBuilder application, for example, an
application could connect to the database in the application Open event, retrieve and update
data in one or more window scripts, and disconnect from the database in the application
Close event.
PowerBuilder
The following statements retrieve and update data using the transaction object EmpSQL and
the DataWindow control dw_emp:
// Connect to the database specified in the
// transaction object EmpSQL
CONNECT USING EmpSQL;
Page 19
DataWindow and DataStore basics
Page 20
DataWindow and DataStore basics
About text
The contents of the edit control are called text. Text is data that has not yet been accepted by
the DataWindow control. Data entered in the edit control is not in a DataWindow buffer yet;
it is simply text in the edit control.
About items
When the user changes the contents of the edit control and presses Enter or leaves the cell (by
tabbing, using the mouse, or pressing up arrow or down arrow), the DataWindow processes
the data and either accepts or rejects it, depending on whether it meets the requirements
specified for the column. If the data is accepted, the text is moved to the current row and
column in the DataWindow Primary buffer. The data in the Primary buffer for a particular
column is referred to as an item.
Events for changing text and items
When data is changed in the edit control, several events occur.
Page 21
DataWindow and DataStore basics
Event Description
ItemError Occurs when new data fails the validation rules for the column
ItemFocusChanged Occurs when the current item in the control changes
1. The DataWindow control converts the text into the correct datatype for the column. For
example, if the user is in a numeric column, the DataWindow control converts the string
that was entered into a number. If the data cannot be converted, the ItemError event is
triggered.
2. If the data converts successfully to the correct type, the DataWindow control applies any
validation rule used by the column. If the data fails validation, the ItemError event is
triggered.
3. If the data passes validation, then the ItemChanged event is triggered. If you set an action/
return code of 1 in the ItemChanged event, the DataWindow control rejects the data and
does not allow the focus to change. In this case, the ItemError event is triggered.
4. If the ItemChanged event accepts the data, the ItemFocusChanged event is triggered next
and the data is stored as an item in a buffer.
Page 22
DataWindow and DataStore basics
You can affect the outcome of events by specifying numeric values in the event's program
code. For example, step 3 above describes how you can force data to be rejected with a code
of 1 in the ItemChanged event.
To specify action/return codes:
• PowerBuilder
Use a RETURN statement
For information about codes for individual events, see DataWindow Reference.
In event code
In addition to these methods, the following events provide access to the text in the edit
control:
EditChanged
ItemChanged
ItemError
Use the Data parameter, which is passed into the event, to access the text of the edit control.
In your code for these events, you can test the text value and perform special processing
depending on that value.
For an example, see Coding the ItemChanged event.
Page 23
DataWindow and DataStore basics
code for the ItemChanged event to do some additional processing. For example, you could
perform some tests, set a code to reject the data, have the column regain focus, and trigger the
ItemError event.
Example
The following sample code for the ItemChanged event for a DataWindow control called
dw_Employee sets the return code in dw_Employee to reject data that is less than the
employee's age, which is specified in a SingleLineEdit text box control in the window.
This is the PowerBuilder version of the code:
int a, age
age = Integer(sle_age.text)
a = Integer(data)
• PowerBuilder
GetItemDate, GetItemDateTime, GetItemDecimal, GetItemNumber, GetItemString,
GetItemTime
• PowerBuilder
SetItem
Page 24
DataWindow and DataStore basics
For example, the following statement, using PowerBuilder syntax, assigns the value from the
empname column of the first row to the variable ls_Name in the Primary buffer:
ls_Name = dw_1.GetItemString (1, "empname")
This PowerBuilder statement sets the value of the empname column in the first row to the
string Waters:
dw_1.SetItem(1, "empname", "Waters")
Uses
You call the GetItem methods to obtain the data that has been accepted into a specific row
and column. You can also use them to check the data in a specific buffer before you update
the database. You must use the method appropriate for the column's datatype.
For more information about the methods listed above, see Chapter 9, Methods for the
DataWindow Control in DataWindow Reference.
Using expressions
DataWindow data expressions refer to single items, columns, blocks of data, selected data, or
the whole DataWindow.
In PowerBuilder, you construct data expressions using dot notation.
Expressions in PowerBuilder
The Object property of the DataWindow control lets you specify expressions that refer
directly to the data of the DataWindow object in the control. This direct data manipulation
allows you to access small and large amounts of data in a single statement, without calling
methods:
dw_1.Object.jobtitle[3] = "Programmer"
The next statement sets the value of the first column in the first row in the DataWindow to
Smith:
dw_1.Object.Data[1,1] = "Smith"
For complete instructions on how to construct DataWindow data expressions, see Chapter 4,
Accessing Data in Code in DataWindow Reference.
Page 25
DataWindow and DataStore basics
Method Purpose
InsertRow Inserts a new row
Reset Clears all rows in the DataWindow control
Retrieve Retrieves rows from the database
RowsCopy, Copies or moves rows from one DataWindow control to another
RowsMove
ScrollToRow Scrolls to the specified row
SelectRow Highlights a specified row
ShareData Shares data among different DataWindow controls.
Update Sends to the database all inserts, changes, and deletions that have been
made in the DataWindow control
For complete information on DataWindow methods, see Chapter 9, Methods for the
DataWindow Control in DataWindow Reference.
• Describe - Reports the values of properties of a DataWindow object and controls within the
DataWindow object
• Modify - Modifies a DataWindow object by specifying a list of instructions that change the
DataWindow object's definition
PowerBuilder
For example, the following statements assign the value of the Border property for the
empname column to a string variable:
Page 26
DataWindow and DataStore basics
string ls_border
ls_border = dw_1.Describe("empname.Border")
The following statement changes the value of the Border property for the empname column
to 1:
dw_emp.Modify("empname.Border=1")
Using expressions
DataWindow property expressions provide access to properties with fewer nested strings. In
PowerBuilder, you can handle problems with incorrect object and property names in the Error
event:
PowerBuilder
Use the Object property and dot notation. For example:
integer li_border
li_border = Integer(dw_1.Object.empname.Border)
dw_1.Object.empname.Border = 1
For reference material on the available variations for property expressions, see the
Section 5.3, “PowerBuilder: DataWindow property expressions” in DataWindow Reference.
• Data items that are invalid (discussed in Manipulating data in a DataWindow control)
This section explains how to handle the last two types of errors.
Page 27
DataWindow and DataStore basics
should not use this type of error checking following a retrieval or update made in a
DataWindow.
For more information about error handling after a SQL statement, see Section 4.1,
“Using Transaction Objects” in Application Techniques.
Table 1.6: Return codes for the Retrieve and Update methods
Method Return code Meaning
Retrieve >=1 Retrieval succeeded; returns
the number of rows retrieved.
-1 Retrieval failed; DBError
event triggered.
0 No data retrieved.
Update 1 Update succeeded.
-1 Update failed; DBError event
triggered.
Example
PowerBuilder
If you want to commit changes to the database only if an update succeeds, you can code:
IF dw_emp.Update() > 0 THEN
COMMIT USING EmpSQL;
ELSE
ROLLBACK USING EmpSQL;
END IF
Page 28
DataWindow and DataStore basics
In many cases you might want to code your own processing in the DBError event and
suppress the default message box. Here are some tips for doing this:
Example
PowerBuilder
Here is a sample script for the DBError event:
// Database error -195 means that some of the
// required values are missing
IF sqldbcode = -195 THEN
MessageBox("Missing Information", &
"You have not supplied values for all " &
+"the required fields.")
END IF
// Return code suppresses default message box
RETURN 1
During execution, the user would see the following message box after the error:
1.2.8.2 Errors in property and data expressions and the Error event
A DataWindow control's Error event is triggered whenever an error occurs in a data or
property expression at execution time. These expressions that refer to data and properties of a
DataWindow object might be valid under some execution-time conditions but not others. The
Error event allows you to respond with error recovery logic when an expression is not valid.
PowerBuilder syntax checking
Page 29
DataWindow and DataStore basics
In PowerBuilder, when you use a data or property expression, the PowerScript compiler
checks the syntax only as far as the Object property. Everything following the Object
property is evaluated at execution time. For example, in the following expression, the column
name emp_name and the property Visible are not checked until execution time:
dw_1.Object.emp_name.Visible = "0"
If the emp_name column did not exist in the DataWindow, or if you had misspelled the
property name, the compiler would not detect the error. However, at execution time,
PowerBuilder would trigger the DataWindow control's Error event.
Using a Try-Catch block
The Error event is triggered even if you have surrounded an error-producing data or property
expression in a Try-Catch block. The catch statement is executed after the Error event is
triggered, but only if you do not code the Error event or do not change the default Error event
action from ExceptionFail!. The following example shows a property expression in a Try-
Catch block:
TRY
dw_1.Object.emp_name.Visible = "0"
CATCH (dwruntimeerror dw_e)
MessageBox ("DWRuntimeError", dw_e.text)
END TRY
Table 1.8: Correspondence between Error event arguments and DWRuntimeError properties
Error event argument DWRuntimeError property
errornumber number
errorline line
errortext text
errorwindowmenu objectname
errorobject class
errorscript routinename
Page 30
DataWindow and DataStore basics
the SystemError event. In the Error event, you can set two arguments passed by reference to
control the outcome of the event.
For a complete description of the arguments of the Error event, see Section 8.21, “Error” in
DataWindow Reference.
Page 31
DataWindow and DataStore basics
Status Applies to
NotModified! 0 Rows and columns
DataModified! 1 Rows and columns
Note
The named values are values of the enumerated datatype dwItemStatus. You must use
the named values, which end in an exclamation point.
A column is included in an UPDATE statement only if the following two conditions are met:
• The column is on the updatable column list maintained by the DataWindow object
For more information about setting the update characteristics of the DataWindow object,
see Chapter 21, Controlling Updates in DataWindow objects in Users Guide.
Page 32
DataWindow and DataStore basics
In the preceding table, Yes means the change is valid. For example, issuing SetItemStatus on
a row that has the status NotModified! to change the status to New! does change the status to
New!. No means that the change is not valid and the status is not changed.
Page 33
DataWindow and DataStore basics
• Write code to perform the processing required to populate the DataWindow control and
print the contents as a report
• Create groups in the DataWindow object to organize the data in the report and force page
breaks when the group values change
• Enhance the DataWindow object to look like a report (for example, you might want to add
a title, column headers, and a computed field to number the pages)
Using fonts
Printer fonts are usually shorter and fatter than screen fonts, so text might not print
in the report exactly as it displays in the DataWindow painter. You can pad the text
Page 34
DataWindow and DataStore basics
fields to compensate for this discrepancy. You should test the report format with a
small amount of data before you print a large report.
For information about the Print method, see the DataWindow Reference. For information
about using nested reports to print multiple DataWindows, see Using nested reports.
Separate DataWindow controls in a single print job
For PowerBuilder applications only
If the window has multiple DataWindow controls, you can use multiple PrintDataWindow
method calls in a script to print the contents of all the DataWindow controls in one print job.
These statements print the contents of three DataWindow controls in a single print job:
int job
job = PrintOpen("Employee Reports")
// Each DataWindow starts printing on a new page.
PrintDataWindow(job, dw_EmpHeader)
PrintDataWindow(job, dw_EmpDetail)
PrintDataWindow(job, dw_EmpDptSum)
PrintClose(job)
For information about PowerBuilder system functions for printing, see Chapter 10,
PowerScript Functions in PowerScript Reference.
Page 35
DataWindow and DataStore basics
You can use the GetChild method on named nested reports in a composite report to get a
reference to a nested report. After getting the reference to the nested report, you can address
the nested report during execution like other DataWindows.
Using this technique, you can call the ShareData method to share data between multiple
updatable DataWindow controls and the nested reports in your composite report. This allows
you to print multiple updatable DataWindows on a page through the composite report.
1. Build a window or form that contains DataWindow controls with the updatable
DataWindow objects.
2. Define a composite report that has reports corresponding to each of the DataWindows in
the window or form that you want to print. Be sure to name each of the nested reports in
the composite report.
3. Add the composite report to the window or form (it can be hidden).
2. Use GetChild to get a reference to the nested reports in the composite report.
3. Use ShareData to share data between the updatable DataWindow objects and the
nested reports.
The report contains the information from the updatable DataWindow objects.
Re-retrieving data
Each time you retrieve data into the composite report, all references (handles) to
nested reports become invalid, and data sharing with the nested reports is terminated.
Therefore, be sure to call GetChild and ShareData each time after retrieving data.
Page 36
DataWindow and DataStore basics
To create a nested report, use the CREATE keyword with the Modify method. Supply the
appropriate values for the nested report's properties.
When creating a nested report, you need to re-retrieve data to see the report. In a composite
report, you can either retrieve data for the whole report or use GetChild to get a reference to
the new nested report and retrieve its data directly. For nested reports in other reports, you
need to retrieve data for the base report.
Destroying nested reports
To destroy a nested report, use the DESTROY keyword with the Modify method. The nested
report disappears immediately.
For more about creating and destroying controls in a DataWindow object or report, see
Dynamically Changing DataWindow Objects.
For a list of properties of nested reports, see Section 3.2.13, “Properties for Report controls in
DataWindow objects” in DataWindow Reference.
If you want users to be able to see the raw data as well as the cross-tabulated data, you can do
one of two things:
• Place two DataWindow controls on the window or form: one that is associated with the
crosstab and one that is associated with a DataWindow object that displays the retrieved
rows.
• Create a composite DataWindow object that contains two reports: one that shows the raw
data and one that shows the crosstab.
Page 37
DataWindow and DataStore basics
With the CrosstabDialog method, you can allow users to redefine which columns in the
retrieved data are associated with the crosstab's columns, rows, and values during execution.
The CrossTabDialog method displays the Crosstab Definition dialog box for the user to
define the data for the crosstab's columns, rows, and values (using the same techniques
you use in the DataWindow painter). When the user clicks OK in the dialog box, the
DataWindow control rebuilds the crosstab with the new specifications.
Displaying informational messages
You can display informational messages when a crosstab is rebuilt during execution as a
result of the call to CrosstabDialog. (The messages are the same ones you see when building
a crosstab in the DataWindow painter, such as Retrieving data and Building crosstab.) You
might want to do this if you are working with a very large number of rows and rebuilding the
crosstab could take a long time.
PowerBuilder
In PowerBuilder, you use a user event to display the crosstab's informational messages.
1. Define a user event for the DataWindow control containing the crosstab. Associate it
with the event ID pbm_dwnmessagetext.
2. In the script for the user event, get the value of the text argument (which holds
the message that PowerBuilder would display when building the crosstab in the
DataWindow painter) and display it to the user.
Examples
PowerBuilder
In the example, code for the DataWindow control's user event for pbm_dwnmessagetext
displays informational messages in a static text control in the window containing the
crosstab:
st_message.Text = text
With that script in place, after CrosstabDialog has been called and the user has redefined
the crosstab, as the crosstab is being rebuilt, your application dynamically displays the
informational messages in the static text control st_message. (You might want to reset
st_message.Text to be the empty string in the line following the CrosstabDialog call.)
In this example, code in the user event for pbm_dwnmessagetext displays informational
messages as MicroHelp in an MDI application (w_crosstab is an MDI frame window):
w_crosstab.SetMicroHelp(text)
The informational messages are displayed in the MDI application's MicroHelp as the crosstab
is rebuilt.
For more information
Page 38
DataWindow and DataStore basics
For more about user events in PowerBuilder, see Chapter 8, Working with User Events in
Users Guide.
For more about the CrosstabDialog method and MessageText event, see Section 9.16,
“CrosstabDialog” in DataWindow Reference and Section 8.32, “MessageText” in
DataWindow Reference.
Table 1.13: Properties you can change on a crosstab DataWindow without forcing a rebuild
Properties Objects
Alignment Column, Compute, Text
Background Column, Compute, Line, Oval, Rectangle,
RoundRectangle, Text
Border Column, Compute, Text
Brush Line, Oval, Rectangle, RoundRectangle
Color Column, Compute, Text
Edit styles (dddw, ddlb, checkbox, edit, Column
editmask, radiobutton, richtext)
Font Column, Compute, Text
Format Column, Compute
Pen Line, Oval, Rectangle, RoundRectangle
Pointer Column, Compute, Line, Oval, Rectangle,
RoundRectangle, Text
Page 39
DataWindow and DataStore basics
For more about the Modify method, see Dynamically Changing DataWindow Objects. For
details on the DataWindow object properties, see Chapter 3, DataWindow Object Properties
in DataWindow Reference.
• Call the SaveAs method to save the contents of a DataWindow directly to a file on disk. To
save the data in HTML format, you need to specify HTMLTable as the file type when you
call SaveAs.
• Call the GenerateHTMLForm method to create an HTML form from data contained in
a DataWindow control or DataStore whose DataWindow object uses the Freeform or
Tabular presentation style.
Page 40
DataWindow and DataStore basics
overlapping controls might not produce the expected results. Nested reports are ignored; they
are not included in the generated HTML.
Example
This example illustrates how you might use DataWindow-generated HTML in an application.
The key line of code gets the HTML from the DataWindow by referring to its HTMLTable
property. In PowerBuilder, you can use the Describe method or a property expression.
PowerBuilder
ls_htmlstring = dw_1.Object.DataWindow.Data.HTMLTable
Page 41
DataWindow and DataStore basics
IF li_Result = -1 THEN
MessageBox("No Browser", "No Browser selected")
END IF
You control table display and style sheet usage through the HTMLTable.GenerateCSS
property. The HTMLTable.GenerateCSS property controls the downward compatibility
of the HTML found in the HTMLTable property. If HTMLTable.GenerateCSS is FALSE,
Page 42
DataWindow and DataStore basics
HTMLTable.GenerateCSS is TRUE
If the HTMLTable.GenerateCSS property is TRUE, the HTMLTable element in the
HTMLTable property uses additional properties to customize table display. For example,
suppose you specify the following properties:
HTMLTable.NoWrap=Yes
HTMLTable.Border=5
HTMLTable.Width=5
HTMLTable.CellPadding=2
HTMLTable.CellSpacing=2
The HTML syntax in the HTMLTable property includes table formatting information and
class references for use with the style sheet:
<table cellspacing=2 cellpadding=2 border=5 width=5>
<tr>
Page 43
DataWindow and DataStore basics
HTMLTable.GenerateCSS is FALSE
If HTMLTable.GenerateCSS is FALSE, the DataWindow does not use HTMLTable
properties to create the Table element. For example, if GenerateCSS is FALSE, the HTML
syntax for the HTMLTable property might look like this:
<table>
<tr>
<th ALIGN=center>Employee ID
<th ALIGN=center>First Name
<th ALIGN=center>Last Name
<tr>
<td ALIGN=right>102
<td>Fran
<td>Whitney
</table>
This technique provides control over HTML page content. Use this technique as an
alternative to calling the SaveAs method with the HTMLTable! Enumeration.
Page 44
DataWindow and DataStore basics
ds_1.SaveAs &
("C:\TEMP\HTMLTemp.htm", HTMLTable!, TRUE)
This creates an HTML file with the proper elements, including the style sheet:
<STYLE TYPE="text/css">
<!--
.2 {COLOR:#000000;BACKGROUND:#ffffff;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:9pt
"Arial", sans-serif;TEXT-DECORATION:none}
.3{COLOR:#000000;BACKGROUND:#ffffff;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:8pt
"MS Sans Serif", sans-serif;TEXT-DECORATION:none}
.3{COLOR:#000000;BACKGROUND:#ffffff;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:8pt
"MS Sans Serif", sans-serif;TEXT-DECORATION:none}
-->
</STYLE>
The GenerateHTMLForm method creates HTML form syntax for DataWindow objects.
You can create an HTML form that displays a specified number of columns for a specified
number of rows. Note the following:
• You create HTML form syntax by calling the GenerateHTMLForm method for the
DataWindow control or DataStore
• The GenerateHTMLForm method creates HTML form syntax for the detail band only
• Embedded nested DataWindows are ignored; they are omitted from the generated HTML
Presentation styles
Although the GenerateHTMLForm method generates syntax for all presentation styles, the
only styles that create usable forms are Freeform and Tabular.
The following HTML page shows a freeform DataWindow object converted into a form
using syntax generated by the GenerateHTMLForm method:
Page 45
DataWindow and DataStore basics
Generating syntax
To generate HTML form syntax, you call the GenerateHTMLForm method:
instancename.GenerateHTMLForm ( syntax, style, action { , startrow, endrow,
startcolumn, endcolumn { , buffer } } )
The method places the Form element syntax into the syntax argument and the HTML style
sheet into the style argument, both of which are passed by reference.
Page 46
DataWindow and DataStore basics
After calling the GenerateHTMLForm method, the ls_syntax variable contains a Form
element. Here is an example:
<FORM ACTION=
"/cgi-bin/pbcgi60.exe/myapp/uo_webtest/f_emplist"
METHOD=POST>
<P>
<P><FONT CLASS=2>Employee ID:</FONT>
<INPUT TYPE=TEXT NAME="emp_id_1" VALUE="501">
<P><FONT CLASS=2>Status:</FONT>
<INPUT TYPE="RADIO" NAME="status_1" CHECKED CLASS=5 ><FONT CLASS=5 >Active
<P>
<INPUT TYPE="RADIO" NAME="status_1" CLASS=5 >
<FONT CLASS=5 >Terminated
<P>
<INPUT TYPE="RADIO" NAME="status_1" CLASS=5 >
<FONT CLASS=5 >On Leave
<P>
<P>
<BR>
<INPUT TYPE=SUBMIT NAME=SAMPLE VALUE="OK">
</FORM>
The ls_stylesheet variable from the previous example contains a Style element, an example of
which is shown below:
<STYLE TYPE="text/css">
<!--
Page 47
DataWindow and DataStore basics
.2{COLOR:#000000;BACKGROUND:#ffffff;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:9pt
"Arial", sans-serif;TEXT-DECORATION:none}
.3{COLOR:#000000;BACKGROUND:#ffffff;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:8pt
"MS Sans Serif", sans-serif;TEXT-DECORATION:none}
.5{COLOR:#000000;BACKGROUND:#ffffff;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:8pt
"MS Sans Serif", sans-serif;TEXT-DECORATION:none}
-->
</STYLE>
ls_html = "<HTML>"
ls_html += as_style
ls_html += "<BODY>"
ls_html += "<H1>Employee Information</H1>"
ls_html += as_syntax
ls_html += "</BODY></HTML>"
RETURN ls_html
Page 48
DataWindow and DataStore basics
during execution using DataWindow methods or property expressions. You can also create
DataWindow objects during execution.
A DataWindow object that is modified or created during execution is called a dynamic
DataWindow object.
What you can do
Using this dynamic capability, you can allow users to change the appearance of the
DataWindow object (for example, change the color and font of the text) or create ad hoc
queries by redefining the data source. After you create a dynamic DataWindow object and
the user is satisfied with the way it looks and the data that is displayed, the user can print the
contents as a report.
Page 49
DataWindow and DataStore basics
DataWindow painter
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
Section 18.3, “Building a DataWindow object” in Users Guide.
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.
Page 50
DataWindow and DataStore basics
To learn how to associate a DataWindow control with a transaction object, see Using
DataWindow Objects.
Using SyntaxFromSQL
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 style.
In PowerBuilder, SyntaxFromSQL is a method of the transaction object. The transaction
object must be connected when you call the method.
• 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.
Page 51
DataWindow and DataStore basics
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 DataWindow object.
This JavaScript example gets the syntax of the DataWindow object in the DataWindow
control, dw_1, and displays it in the text box control, textb_dw_syntax:
var dwSyntax;
dwSyntax = dw_1.Describe("datawindow.syntax");
textb_dw_syntax.value = dwSyntax;
Limitations
You cannot use query mode in a DataWindow object that contains the UNION
keyword or nested SELECT statements.
Once the DataWindow is in query mode, users can specify selection criteria using query by
example -- just as you do when you use Quick Select to define a data source. When criteria
have been defined, they are added to the WHERE clause of the SELECT statement the next
time data is retrieved.
The following three figures show what happens when query mode is used.
First, data is retrieved into the DataWindow. There are 36 rows:
Page 52
DataWindow and DataStore basics
Next, query mode is turned on. The retrieved data disappears and users are presented with
empty rows where they can specify selection criteria. Here the user wants to retrieve rows
where Quarter = Q1 and Units > 15:
Next, Retrieve is called and query mode is turned off. The DataWindow control adds the
criteria to the SELECT statement, retrieves the three rows that meet the criteria, and displays
them to the user:
Page 53
DataWindow and DataStore basics
You can turn query mode back on, allow the user to revise the selection criteria, and retrieve
again.
In JavaScript:
dw_1.Modify("datawindow.querymode=yes");
All data displayed in the DataWindow is blanked out, though it is still in the
DataWindow control's Primary buffer, and the user can enter selection criteria where the
data had been.
2. The user specifies selection criteria in the DataWindow, just as you do when using
Quick Select to define a DataWindow object's data source.
Criteria entered in one row are ANDed together; criteria in different rows are ORed.
Valid operators are =, <>, <, >, <=, >=, LIKE, IN, AND, and OR.
For more information about Quick Select, see Section 18.5, “Using Quick Select” in
Users Guide.
3. Call AcceptText and Retrieve, then turn off query mode to display the newly retrieved
rows.
In PowerBuilder:
dw_1.AcceptText()
dw_1.Modify("datawindow.querymode=no")
Page 54
DataWindow and DataStore basics
dw_1.Retrieve()
In JavaScript:
dw_1.AcceptText();
dw_1.Modify("datawindow.querymode=no");
dw_1.Retrieve();
The DataWindow control adds the newly defined selection criteria to the WHERE
clause of the SELECT statement, then retrieves and displays the specified rows.
Page 55
DataWindow and DataStore basics
In JavaScript:
dw_1.Modify("datawindow.queryclear=yes");
In JavaScript:
dw_1.Modify("datawindow.querysort=yes");
In JavaScript:
dw_1.Modify("mycolumn.criteria.override_edit=yes");
You can also specify this in the DataWindow painter by checking Override Edit on the
General property page for the column. With properties overridden for criteria, users can
specify any number of characters in a cell (they are not constrained by the number of
characters allowed in the column in the database).
Forcing users to specify criteria for a column
You can force users to specify criteria for a column during query mode by coding the
following:
In PowerBuilder:
dw_1.Modify("mycolumn.criteria.required=yes")
In JavaScript:
dw_1.Modify("mycolumn.criteria.required=yes");
You can also specify this in the DataWindow painter by checking Equality Required on the
General property page for the column. Doing this ensures that the user specifies criteria for
Page 56
DataWindow and DataStore basics
the column and that the criteria for the column use = rather than other operators, such as < or
>=.
• The LibraryDirectory function to obtain a list of DataWindow objects and other library
entries in the current library
• A DropDownListBox to list the DataWindow objects in the library and then allow the user
to select a DataWindow from the list
• The LibraryExport function to export the selected DataWindow object syntax into a string
variable
• The Create method to use the DataWindow syntax to create the DataWindow object in the
specified DataWindow control
• The Describe method to get the current DataWindow object syntax, for example:
string dwSyntax
dwSyntax = dw_1.Describe("datawindow.syntax")
• The Modify method to allow the user to modify the DataWindow object
For information about the PowerScript functions, see Chapter 10, PowerScript Functions in
PowerScript Reference. For information about the DataWindow methods Create, Describe,
and Modify, see Chapter 9, Methods for the DataWindow Control in DataWindow Reference.
• Describe
Page 57
DataWindow and DataStore basics
Select an object type from the Object dropdown listbox. In the Attributes listbox, select
the property you want to describe. The bottom of the window displays Describe and dot
notation statements.
• Modify
• Attributes
Select an object type and the property you want to modify. The bottom of the window
displays Modify and dot notation statements.
• Create
Select the object type that you want to create. The bottom of the window displays a
Modify statement.
• Destroy
Select the object type that you want to destroy. The bottom of the window displays a
Modify statement.
• SyntaxFromSQL
On each tab, select the properties you want to include in the arguments for the
SyntaxFromSQL function. Notice that you can select multiple tabs and multiple properties
per object for SyntaxFromSQL. When you have finished selecting properties, click Build
Syntax to display the SyntaxFromSQL function at the bottom of the window.
1.3.7.1 Describe
Reports the values of properties of a DataWindow object and objects within the DataWindow
object. Each column and graphic object in the DataWindow has a set of properties. You
specify one or more properties as a string and Describe returns the values of the properties.
1.3.7.2 Modify
Modifies a DataWindow object by applying specifications, specified as a list of instructions,
that change the DataWindow object's definition. You can change appearance, behavior, and
database information for the DataWindow object by changing the values of properties. You
can add and remove objects from the DataWindow object by providing specifications for the
objects.
1.3.7.3 Create
Creates a DataWindow object using DataWindow source code and puts that object in the
specified DataWindow control. This "dynamic" DataWindow object does not become a
permanent part of the application source library.
1.3.7.4 Destroy
Deletes a DataWindow object. This dynamic DataWindow object change does not become a
permanent part of the application source library.
Page 58
DataWindow and DataStore basics
1.3.7.5 SyntaxFromSQL
Generates DataWindow source code based on a SQL SELECT statement and Style. A full
presentation string has the format:
"Style(Type= value property=value ...) DataWindow(property = value...)
Column(property = value...)
Group(groupby_col1 groupby_col2 ... property...)
Text(property = value...)
Title('titlestring')"
• Anything surrounded by <> indicates that a real value must be substituted (without
surrounding <>). All other syntax is correct as is including single quotes.
• Internal to PowerBuilder, all DataWindow object properties are stored in strings. These can
represent strings, numbers, or boolean (1/0, yes/no).
Where appropriate the compiler allows for the assigning of numbers or booleans and converts
them to strings automatically. When these same property values are read they are returned as
a string for the Describe syntax and as an Any variable for dot notation syntax.
Examples
The DataWindow readonly property is stored as 'yes' or 'no'.
Each of the following syntax statements sets the property to 'yes'.
dw_1.Modify("DataWindow.ReadOnly=Yes")
dw_1.Modify("DataWindow.ReadOnly=True")
dw_1.Object.DataWindow.ReadOnly = 'Yes'
dw_1.Object.DataWindow.ReadOnly = True
Page 59
DataWindow and DataStore basics
• Perform background processing against the database without having to hide DataWindow
controls in a window
Suppose that the DataWindow object displayed in a DataWindow control is suitable for
online display but not for printing. In this case, you could define a second DataWindow
object for printing that has the same result set description and assign this object to a
DataStore. You could then share data between the DataStore and the DataWindow control.
Whenever the user asked to print the data in the window, you could print the contents of
the DataStore.
DataStore methods
Most of the methods and events available for DataWindows are also available for DataStores.
However, some of the methods that handle online interaction with the user are not available.
For example, DataStores support the Retrieve, Update, InsertRow, and DeleteRow methods,
but not GetClickedRow and SetRowFocusIndicator.
Prompting for information
When you are working with DataStores, you cannot use functionality that causes a dialog
box to display to prompt the user for more information. Here are some examples of ways to
overcome this restriction:
Page 60
DataWindow and DataStore basics
Page 61
DataWindow and DataStore basics
data, you need to set the transaction object for the DataStore. Once these setup steps have
been performed, you can retrieve data into the DataStore, share data with another DataStore
or DataWindow control, or perform other processing.
Examples
The following script uses a DataStore to retrieve data from the database. First it instantiates
the DataStore object and assigns a DataWindow object to the DataStore. Then it sets the
transaction object and retrieves data into the DataStore:
datastore lds_datastore
lds_datastore = CREATE datastore
lds_datastore.DataObject = "d_cust_list"
lds_datastore.SetTransObject (SQLCA)
lds_datastore.Retrieve()
/* Perform some processing on the data... */
1. In the User Object painter, define and save a standard class user object inherited from the
built-in DataStore object.
Once you have defined a custom DataStore in the User Object painter, you can write code
that uses the user object to perform the processing you want.
For instructions on using the User Object painter in PowerBuilder, see Section 15.2, “About
the User Object painter” in Users Guide.
1. Select Standard Class User Object on the PBObjects tab in the New dialog box.
2. Select datastore as the built-in system type that you want your user object to inherit
from, and click OK.
The User Object painter workspace displays so that you can define the custom object.
3. Specify the name of the DataWindow object in the DataObject box in the Properties
view and click OK.
4. Customize the DataStore by scripting the events for the object, or by defining methods,
user events, and instance variables.
Page 62
DataWindow and DataStore basics
1. Select the object or control for which you want to write a script.
2. Open the Script view and select the event for which you want to write the script.
3. Write code that uses the user object to do the necessary processing.
Here is a simple code example that shows how to use a custom DataStore to retrieve
data from the database. First it instantiates the custom DataStore object, then it sets the
transaction object and retrieves data into the DataStore:
uo_cust_dstore lds_cust_dstore
lds_cust_dstore = CREATE uo_cust_dstore
lds_cust_dstore.SetTransObject (SQLCA)
lds_cust_dstore.Retrieve()
/* Perform some processing on the data... */
Notice that this script does not assign the DataWindow object to the DataStore. This is
because the DataWindow object is specified in the user object definition.
Page 63
DataWindow and DataStore basics
For more information on accessing data in a DataStore, see Chapter 4, Accessing Data in
Code in DataWindow Reference.
About the DataStore buffers
Like a DataWindow control, a DataStore uses three buffers to manage data:
Table 1.15: DataStore buffers
Buffer Contents
Primary Data that has not been deleted or filtered out (that is, the rows that are
viewable)
Filter Data that was filtered out
Delete Data that was deleted by the user or in a script
For information about DataStore methods, see Chapter 9, Methods for the DataWindow
Control in DataWindow Reference.
Page 64
DataWindow and DataStore basics
You can also share data between two DataWindow objects where the source of one is a
database and the source of the other is external. As long as the lists of columns and their
datatypes match, you can share the data.
What is shared?
When you use the ShareData method, the following information is shared:
Primary buffer
Delete buffer
Filter buffer
Sort order
ShareData does not share the formatting characteristics of the DataWindow objects. That
means you can use ShareData to apply different presentations to the same result set.
When you alter the result set
Page 65
DataWindow and DataStore basics
If you perform an operation that affects the result set for either the primary or the secondary
DataWindow, the change affects both of the objects sharing the data. Operations that alter
the buffers or the sort order of the secondary DataWindows are rerouted to the primary
DataWindow. For example, if you call the Update method for the secondary DataWindow,
the update operation is applied to the primary DataWindow also.
Turning off sharing data
To turn off the sharing of data, you use the ShareDataOff method. When you call
ShareDataOff for a primary DataWindow, any secondary DataWindows are disassociated
and no longer contain data. When you call ShareDataOff for a secondary DataWindow, that
DataWindow no longer contains data, but the primary DataWindow and other secondary
DataWindows are not affected.
In most cases you do not need to turn off sharing, because the sharing of data is turned
off automatically when a window is closed and any DataWindow controls (or DataStores)
associated with the window are destroyed.
Crosstabs
You cannot share data with a DataWindow object that has the Crosstab presentation style.
The DataWindow object displayed in the DataWindow control is suitable for online display
but not for printing. In this case, you could define a second DataWindow object for printing
that has the same result set description as the object used for display and assign the second
Page 66
DataWindow and DataStore basics
object to a DataStore. You could then share data between the DataStore and the DataWindow
control. Whenever the user asked to print the data in the window, you could print the contents
of the DataStore.
When the window or form opens
The code you write begins by establishing the hand pointer as the current row indicator
for the dw_employees DataWindow control. Then the script sets the transaction object for
dw_employees and issues a Retrieve method to retrieve some data. After retrieving data,
the script creates a DataStore using the instance variable or data member ids_datastore, and
assigns the DataWindow object d_employees to the DataStore. The final statement of the
script shares the result set for the dw_employees DataWindow control with the DataStore.
This code is for the window's Open event:
dw_employees.SetRowFocusIndicator(Hand!)
dw_employees.SetTransObject(SQLCA)
dw_employees.Retrieve()
Page 67
DataWindow and DataStore basics
When the Employee Salary Information radio button is selected, the window displays a graph
that shows employee salary information by department:
This window has one DataWindow control called dw_display. It uses two DataStores to
process data retrieved from the database. The first DataStore (ids_emp_list) shares its result
set with the second DataStore (ids_emp_graph). The DataWindow objects associated with the
two DataStores have the same result set description.
When the window or form opens
When the window or form opens, the application sets the mouse pointer to the hourglass
shape. Then the code creates the two DataStores and sets the DataWindow objects for the
DataStores. Next the code sets the transaction object for ids_emp_list and issues a Retrieve
method to retrieve some data.
Page 68
DataWindow and DataStore basics
After retrieving data, the code shares the result set for ids_emp_list with ids_emp_graph. The
final statement triggers the Clicked event for the Employee List radio button.
This code is for the window's Open event:
SetPointer(HourGlass!)
ids_emp_list = Create DataStore
ids_emp_graph = Create DataStore
ids_emp_list.DataObject = "d_emp_list"
ids_emp_graph.DataObject = "d_emp_graph"
ids_emp_list.SetTransObject(sqlca)
ids_emp_list.Retrieve()
ids_emp_list.ShareData(ids_emp_graph)
rb_emp_list.EVENT Clicked()
Page 69
DataWindow and DataStore basics
Supported environment
PowerBuilder
Graphs are supported. Because you can print DataStores, PowerBuilder provides
some events and functions for DataStores that pertain to the visual presentation of
the data. However, graph functions such as CategoryCount, CategoryName, GetData,
SeriesCount, and so forth depend on the visual graph control, which is not created for
a DataStore. These functions return an error value or an empty string when used with
DataStore objects.
It is common for developers to design DataWindow objects that include one or more graphs.
When users need to quickly understand and analyze data, a bar, line, or pie graph can often be
the most effective format to display.
To learn about designing graphs, see Chapter 26, Working with Graphs in Users Guide.
Working with graphs in your code
The following sections describe how you can access (and optionally modify) a graph by
addressing its properties in code at execution time. There are two kinds of graph properties:
Page 70
DataWindow and DataStore basics
You can change these graph properties at execution time by assigning values to the graph's
properties in code.
Property expressions
PowerBuilder
You can modify properties using property expressions. For example, to change the type of the
graph gr_emp to Column, you could code:
dw_empinfo.Object.gr_emp.GraphType = ColGraph!
To change the title of the graph at execution time, you could code:
dw_empinfo.Object.gr_emp.Title = "New title"
Modify method
You can use the Modify method to reference parts of a graph.
Example for PowerBuilder
For example, to change the title of graph gr_emp in DataWindow control dw_empinfo, you
could code:
dw_empinfo.Modify("gr_emp.Title = 'New title'")
For a complete list of graph properties, see Section 3.2.5, “Properties for Graph controls in
DataWindow objects” in DataWindow Reference.
Page 71
DataWindow and DataStore basics
string FaceName
int TextSize
boolean Italic
...
grAxis Values, Category, Series
boolean AutoScale
int MajorDivisions
int MinorDivisions
string Label
...
For a complete list of graph properties, see Section 3.2.5, “Properties for Graph controls in
DataWindow objects” in DataWindow Reference.
You can use the PowerBuilder Browser to examine the properties of a DataWindow object
that contains a graph. For more information, see the Users Guide.
• Methods that change the color, fill patterns, and other visual properties of data
For example, there is a method CategoryCount, which returns the number of categories in
a graph. So to get the category count in the graph gr_printer (which is in the DataWindow
control dw_sales), write:
Ccount = dw_sales.CategoryCount("gr_printer")
Page 72
DataWindow and DataStore basics
PowerBuilder
These methods get information about the data and its display. For several of them, an
argument is passed by reference to hold the requested information:
Page 73
DataWindow and DataStore basics
• PowerBuilder
Event ID pbm_dwngraphcreate, which you can assign to a user event for a DataWindow
control (described below)
The graph-creation event is triggered by the DataWindow control after it has created a graph
and populated it with data, but before it has displayed the graph. By accessing the data in the
graph in this event, you are assured that you are accessing the current data and that the data
displays the way you want it.
Setting up the PowerBuilder user event
PowerBuilder provides an event ID, pbm_dwngraphcreate, that you can assign to a user event
for a DataWindow control.
1. Place the DataWindow control in a window or user object and associate it with the
DataWindow object containing the graph.
Next you create a user event for the DataWindow control that is triggered whenever a
graph in the control is created or changed.
Page 74
DataWindow and DataStore basics
3. Select the DataWindow control in the first drop-down list of the prototype window.
If the second drop-down list also changes to display an existing DataWindow event
prototype, scroll to the top of the list to select New Event or select Insert>Event once
again from the menu bar.
7. Write a script for the new GraphCreate event that accesses the data in the graph.
Calling data access methods in the GraphCreate event assures you that the data access
happens each time the graph has been created or changed in the DataWindow.
Examples
Page 75
DataWindow and DataStore basics
PowerBuilder
The following statement sets to black the foreground (fill) color of the Q1 series in the
graph gr_quarter, which is in the DataWindow control dw_report. The statement is in
the GraphCreate event, which is associated with the event ID pbm_dwngraphcreate in
PowerBuilder:
dw_report.SetSeriesStyle("gr_quarter", "Q1", &
foreground!, 0)
The following statement changes the foreground (fill) color to red of the second data point in
the Stellar series in the graph gr_sale in a window. The statement can be in a script for any
event:
int SeriesNum
// Get the number of the series.
SeriesNum = gr_sale.FindSeries("Stellar")
• PowerBuilder
Write a Clicked script for the DataWindow control
You should call ObjectAtPointer in the first statement of the event's code.
Using ObjectAtPointer
ObjectAtPointer works differently in PowerBuilder.
PowerBuilder
ObjectAtPointer has this syntax:
DataWindowName.ObjectAtPointer ( "graphName", seriesNumber, dataNumber )
Page 76
DataWindow and DataStore basics
The object is identified by a grObjectType enumerated value. For example, if the user
clicks on a data point, ObjectAtPointer returns TypeData!. If the user clicks on the graph's
title, ObjectAtPointer returns TypeTitle!.
For a list of object values, see Chapter 6, DataWindow Constants in DataWindow
Reference. In PowerBuilder, you can also open the Browser and click the Enumerated tab.
• Stores the number of the series the pointer was over in the variable seriesNumber, which is
an argument passed by reference
• Stores the number of the data point in the variable dataNumber, also an argument passed
by reference
Example
Assume there is a graph named gr_sales in the DataWindow control dw_sales. The following
code for the control's MouseDown event displays a message box:
• If the user clicks on a series (that is, if ObjectAtPointer returns 1), the message box shows
the name of the series clicked on. The example uses the method GetSeriesName to get the
series name, given the series number stored by ObjectAtPointer.
• If the user clicks on a data point (that is, if ObjectAtPointer returns 2), the message box
lists the name of the series and the value clicked on. The example uses GetDataNumber to
get the data's value, given the data's series and data point number.
PowerBuilder
This code is for the Clicked event:
int SeriesNum, DataNum
double Value
grObjectType ObjectType
string SeriesName, ValueAsString
string GraphName
GraphName = "gr_sale"
Page 77
DataWindow and DataStore basics
The XHTML export template is a single-instance document of the <form> element. It stores
only the structural layout and any changes that you make to the elements, attributes, and style
declarations. When XHTML is generated, these changes are incorporated into the <form>
element and the CSS stylesheet used to render the DataWindow in the browser. More than
one export template can be created for a DataWindow.
Default style rules and most default attributes are not stored in the template. Any changes to
style declarations are stored in the template, but at runtime they are removed and applied to
the separately generated CSS stylesheet.
In the Export Template view for XHTML, you can reference DataWindow column, computed
field, and text controls, and DataWindow expressions for each row in the XHTML, wherever
character data is allowed. At runtime, these are replaced with text.
Page 78
DataWindow and DataStore basics
You can create multiple templates and save them by name with the DataWindow object.
Each template is uniquely associated with the DataWindow object open in the painter. For
information, see "Managing templates".
Table 1.20: Icons used in the Export Template view for XHTML
Icon Description
Root or child element
Page 79
DataWindow and DataStore basics
Literal text
CDATA section
Nested report
Page 80
DataWindow and DataStore basics
Table 1.21:
Menu item Description
New Default Define a new default XHTML export template based on the current
DataWindow layout
Open Open a saved template
Save Save the current template; if the template has no name, name it
Save As Save the current template with a new name
Delete Delete the current template (enabled only if more than one template exists
for the current DataWindow object)
Page 81
DataWindow and DataStore basics
Table 1.22:
Elements Name defaults to
Root <form> DataWindow name_dataForm
Header <div> DataWindow name_band1
Detail <div> DataWindow name_bandn
Summary <div> DataWindow name_bandn
Footer <div> DataWindow name_bandn
Child elements of the Header, Detail, Name of each DataWindow control.
Summary, and Footer elements
The template is stored inside the DataWindow object in the PBL. After saving a template
with a DataWindow object, you can see its definition in the Source editor for the
DataWindow object. For example, this is part of the source for a DataWindow that has two
templates. The templates have required elements only:
export.xhtml(usetemplate = "t_phone"
template = (name = "t_address"
comment = "Employee Address Book" xhtml = "<...>")
template = (name = "t_phone"
comment = "Employee Phone Book" xhtml = "<...>") )
Note
Defining multiple templates You can define multiple templates for a single
DataWindow object. One reason you might do this is to vary the edit styles generated
for the same DataWindow edit control.
Page 82
DataWindow and DataStore basics
The Data Export page in the Properties view lets you set properties for exporting data in
XHTML. The names of all templates that you create and save for the current DataWindow
object display in the Use Template drop-down list.
In addition to the properties that you can set on this page, you can use the
Export.XHTML.TemplateCount and Export.XHTML.Template[ ].Name properties to let the
user of an application select an export template at runtime. See "Selecting XHTML export
templates at runtime".
You can specify the template you want to apply to the default XML Web
DataWindow or XHTML Web DataWindow generation at runtime by setting the
Export.XHTML.UseTemplate property. You set the property using the Data Export tab in the
DataWindow painter's Properties view by selecting XHTML as the format and then selecting
the XHTML export template's name from the Use Template drop-down list box.
You can also set the Export.XHTML.UseTemplate DataWindow property in script. For
information, see "Selecting XHTML export templates at runtime".
Page 83
DataWindow and DataStore basics
Export.XHTML.TemplateCount
Read only, so no user The number of XHTML export templates
interface field. associated with a DataWindow object
Export.XHTML.Template[num].Name
Read only, so no user The name of an XHTML export
interface field. template associated with a DataWindow
object returned by index value that
ranges from 1 to the value of the
Export.XHTML.TemplateCount property
Export.XHTML.UseTemplate
Select a template from the The name of an XHTML export template
Use Template drop–down (previously saved in the DataWindow
list box in the Data Export painter) that optionally controls the logical
tab in the DataWindow structure of the XHTML generated by a
painter's Properties view. DataWindow object
Page 84
DataWindow and DataStore basics
The items in the Header section are generated only once at runtime (when the DataWindow
is exported to XHTML), unless the DataWindow is a Group DataWindow. For Group
DataWindows, the corresponding XHTML fragment in the Header section is repeated so that
it iteratively heads each group detail—the group of XHTML rows corresponding to the group
specified in the DataWindow.
The Header section contains the rendering of the DataWindow header band and any group
header bands. Bands are generated within <div> elements. The controls rendered in the
Header section (such as computed titles and text control column headings) are typically also
generated within <div> elements, with referenced content.
These entities are generated only once and are not iterated for each row. However, for
DataWindows with group headers, the corresponding XHTML fragment in the Header
section is repeated, iteratively heading each group of XHTML rows corresponding to the
group specified in the DataWindow.
The Detail section contains the rendering of the DataWindow Detail band, delimited by
the first <div> element. The <div> element's contents represent a single row instance to be
generated iteratively. Any group trailers, summary band, and footer band are also appended
and enclosed by <div> elements. The controls rendered in the Detail section (for example,
column, computed field, DropDownDataWindow, DropDownListBox, checkbox, and
button controls) are usually also generated within <div>, <input>, or <select> elements with
referenced content.
Page 85
DataWindow and DataStore basics
The Detail section can contain the items listed in the following table.
Page 86
DataWindow and DataStore basics
If an element has no attributes, you can edit its tag in the Export Template view for XHTML
by selecting it and left-clicking the tag or pressing F2. Literal text nodes can be edited in the
same way. You can delete items (and their children) by pressing the Delete key.
The root element of the XHTML export template is the XHTML <form> element. You can
change the name of the root element and add attributes and children.
Changing the name of the root element changes the name of its start and end tags. You can
change the name using the Edit Attributes menu item to display the Element Attributes dialog
box. For information about editing attributes, see "Element attributes".
You can add the following kinds of children to the root element:
• Elements
• Text
• CDATA sections
Adding a DataWindow control reference opens a dialog box containing a list of the columns,
computed fields, report controls, and text controls in the document.
Page 87
DataWindow and DataStore basics
Control references can also be added to empty attribute values or element contents using drag
and drop from the Control List view. Column references can also be added using drag-and-
drop from the Column Specifications view.
Page 88
DataWindow and DataStore basics
Using the previous example, if the short date format in the registry is mm/dd/yy, and the
DataWindow expression is: "Start Date is " + start_date, the XHTML output
is Start Date is 12/27/02.
Select Edit Attributes from the pop-up menu for elements to edit an existing attribute or add a
new one. The attributes that display include all the default attributes for the elements with any
template changes applied. The name attribute (and in some cases the class attribute) used to
identify the element is omitted and cannot be changed.
You can change or delete the default attribute values or add new ones. Controls or
expressions can also be referenced for element attribute values.
For each attribute specified, you can select a control reference from the drop–down list or
enter a literal text value. A literal text value takes precedence over a control reference. You
can also use the expression button to the right of the Text box to enter an expression.
The expression button and entry operates similarly to DataWindow object properties in the
Properties view. The button shows a green equals sign if an expression has been entered,
and a red not-equals sign if not. A control reference or text value specified in addition to the
expression is treated as a default value. In the template, this combination is stored with the
control reference or text value, followed by a tab, preceding the expression. For example:
attribute_name=~"text_val~~tdw_expression~"
When you finish modifying element attributes and you click OK, only changes are stored in
the template. Default attributes that are deleted are added in the template and marked with an
empty value.
If you right-click an element and select Edit Styles from the pop-up menu, the Style
Declarations dialog box displays the read-only set of default style declarations for the
element on the left:
Page 89
DataWindow and DataStore basics
For clarity, style declarations are omitted from the XHTML export template. You can add
new style declarations or override the existing ones by declaring them on the right side, or
remove them by adding them with an empty value.
This dialog displays the current JavaScript event handlers, if any. You can add new event
handlers or override the existing ones by declaring them on the right side, or remove them by
adding them with an empty value.
Page 90
DataWindow and DataStore basics
parser, it should be defined as a CDATA section. A CDATA section starts with <![CDATA[
and ends with ]]>. CDATA sections cannot be nested, and there can be no white space
characters inside the ]]> delimiter—for example, you cannot put a space between the two
square brackets.
Example
<![CDATA[
do not parse me
]]>
• Style declarations
• Element attributes
The dialogs first display these specifications as they would be generated at runtime by
default. The painter gets these from the XML Web Generator in DWE in real-time, read-
Page 91
DataWindow and DataStore basics
only display on one half of the dialog. Within input field(s) on the other half of the dialog,
the developer can override these specifications at the atomic declaration or attribute level.
This includes resetting included declarations/attributes, setting declarations/attributes not
included, or removing declarations/attributes. These change specifications will then persist
in the XHTML export template, and be applied to the default presentation generated by the
XML Web Generator at runtime.
Before generating the XHTML, set the export template using the text in the drop–down list
box:
dw_1.Object.DataWindow.Export.XHTML.UseTemplate= ddlb_1.text
When you export the DataWindow or DataStore object, PowerBuilder uses an export
template to specify the content of the generated XML.
Page 92
DataWindow and DataStore basics
ls_xmlstring = dw_1.Object.DataWindow.Data.XHTML
ls_xmlstring = dw_1.Describe("DataWindow.Data.XHTML")
When you export the DataWindow or DataStore object, PowerBuilder uses an export
template to specify the content of the generated XHTML and CSS style sheet.
Page 93
Index
Page 94
Index
I
ItemChanged event, 23
ItemError event, 24
M
Modify (DWSyntax), 58
P
presentation styles, 6
Q
query mode, 52
R
retrieval arguments, 18
S
SyntaxFromSQL (DWSyntax), 59
T
transaction management, 15
W
Web service data source
access, 20
Page 95