PowerBuilder objects

The basic building blocks of a PowerScript target are objects:

Table 1-2: Basic building blocks of a PowerScript target

Object

Use

Application

Entry point into an application

Window

Primary interface between the user and a PowerBuilder application

DataWindow

Retrieves and manipulates data from a relational database or other data source

Menu

List of commands or options that a user can select in the currently active window

Global function

Performs general-purpose processing

Query

SQL statement used repeatedly as the data source for a DataWindow object

Structure

Collection of one or more related variables grouped under a single name

User object

Reusable processing module or set of controls, either visual or nonvisual

Pipeline

Reproduces data within a database or across databases

Project

Packages application for distribution to users

These objects are described in more detail in the sections that follow.

Application object

The Application object is the entry point into an application. It is a discrete object that is saved in a PowerBuilder library (PBL file), just like a window, menu, function, or DataWindow object.

The Application object defines application-level behavior, such as which fonts are used by default for text, and what processing should occur when the application begins and ends.

When a user runs the application, an Open event is triggered in the Application object. The script you write for the Open event initiates the activity in the application. When the user ends the application, the Close event in the Application object is triggered.

The script you write for the Close event typically does all the cleanup required, such as closing a database or writing to a preferences file. If there are serious errors during execution that are not caught using PowerBuilder’s exception handling mechanism, the Application object’s SystemError event is triggered.

Figure 1-1: Application life cycle

Shown is a flow diagram of the application life cycle. First the user starts the application, which triggers the open event in the application object. An Initial window opens and the environment is set up. If a system error occurs now or later in the cycle, it triggers the System Error event in the application object. The user interacts with the window, and the application runs. Windows open and close, data is retrieved or written to the databse, and so on. Then the user ends the application, which triggers the close event in the application object. The windows close and cleanup is done.

Windows

Windows are the primary interface between the user and a PowerBuilder application. Windows can display information, request information from a user, and respond to the user’s mouse or keyboard actions.

A window consists of:

Windows can have various kinds of controls, as illustrated in the following picture:

Shown is a window with many types of controls, described in the text.

On the left of the window is a DataWindow control with horizontal and vertical trackbars. On the right is a group box that contains static text controls (containing descriptive labels), edit mask controls (as they appear when the SpinControl property is on), a check box, and two smaller group boxes with radio buttons. Under the main group box is a command button.

DataWindow objects

A DataWindow object is an object that you use to retrieve and manipulate data from a relational database or other data source (such as an Excel worksheet or dBASE file).

Presentation styles DataWindow objects also handle the way data is presented to the user. You can choose from several presentation styles. For example, you can display the data in Tabular or Freeform style.

There are many ways to enhance the presentation and manipulation of data in a DataWindow object. For example, you can include computed fields, pictures, and graphs that are tied directly to the data retrieved by the DataWindow.

The Data Window example includes a picture, information, and a graph.

Display formats, edit styles, and validation You can specify how to display the values for each column, and you can validate data entered by users in a DataWindow object. You do this by defining display formats, edit styles, and validation rules for columns.

For example:

Web DataWindow Using the XML Web DataWindow, the XHTML Web Data Window, or the HTML Web DataWindow, you can generate DataWindow objects in XML (with subsequent XSLT transformation to XHTML), XHTML directly, or HTML and display them in a browser, using a PowerBuilder component running in either EAServer or COM+ to generate the Web DataWindow.

Menus

Menus are lists of items that a user can select from a menu bar for the active window. The items on a menu are usually related. They provide the user with commands (such as Open and Save As on the PowerBuilder File menu) or alternate ways of performing a task (for example, the items on the Edit menu in the Window painter correspond to buttons in the PainterBar).

You can select menu items with the mouse or with the keyboard, or use accelerator (mnemonic access) keys defined for the items. You can define your own keyboard shortcuts for any PowerBuilder menu item from a dialog box that you open with the Tools>Keyboard Shortcuts menu item.

A drop-down menu is a menu under an item in the menu bar. A cascading menu is a menu that appears to the side of an item in a drop-down menu.

Shown is a window with the Data menu item selected. Under Data is a drop-down menu. A menu item is selected, showing an example of a cascading menu to the right.

Each choice in a menu is defined as a Menu object in PowerBuilder. The preceding window shows two Menu objects on the menu bar (File and Data), three Menu objects on the drop-down Data menu (Update, Delete, and Cancel), and two Menu objects on the cascading menu beside Update (Current Row and All Rows).

Global functions

PowerBuilder lets you define two types of functions:

Queries

A query is a SQL statement that is saved with a name so that it can be used repeatedly as the data source for a DataWindow object. Queries enhance developer productivity, because they can be coded once but reused as often as necessary.

Structures

A structure is a collection of one or more related variables of the same or different data types grouped under a single name. In some languages, such as Pascal and COBOL, structures are called records.

Structures allow you to refer to related entities as a unit rather than individually. For example, you can define the user’s ID, address, access level, and a picture (bitmap) of the employee as a structure called user_struct, and then refer to this collection of variables as user_struct.

There are two kinds of structures:

User objects

Applications often have features in common. For example, several applications might have a Close button that performs a certain set of operations and then closes the window, or they might have DataWindow controls that perform the same type of error checking. Several applications might all require a standard file viewer.

If you find yourself using the same application feature repeatedly, you should define a user object. You define the user object once and use it as many times as you need.

User objects can be visual or nonvisual. They can be further divided into standard or custom user objects. Standard user objects, whether visual or nonvisual, are system objects that are always available with PowerBuilder. You can also use controls for external visual objects that were created outside PowerBuilder. The main types of user objects are:

Libraries

You save objects, such as windows and menus, in PowerBuilder libraries (PBL files). When you run an application, PowerBuilder retrieves the objects from the library. Applications can use as many libraries as you want. When you create an application, you specify which libraries it uses.

Projects

You can create Project objects that build executable applications and components you can deploy to a server, as well as proxy objects you use in EAServer applications.