Introduction to PowerBuilder

About this chapter

This chapter introduces the PowerBuilder development environment, which you use in the tutorials in Parts 2-4. It also describes the building blocks of a PowerBuilder application.

For more information

For a more detailed description of the PowerBuilder development environment, see The PowerBuilder Environment in Users Guide.

What PowerBuilder is

PowerBuilder is an enterprise development tool that allows you to build many types of applications and components. It is one of a group of Appeon products that together provide the tools to develop client/server, multitier, and Internet applications.

What's in a PowerBuilder application?

A PowerBuilder client application can contain:

  • A user interface

    Menus, windows, and window controls that users interact with to direct an application.

  • Application processing logic

    Event and function scripts in which you code business rules, validation rules, and other application processing. PowerBuilder allows you to code application processing logic as part of the user interface or in separate modules called custom class user objects.

PowerBuilder applications are event driven

In a client application, users control what happens by the actions they take. For example, when a user clicks a button, chooses an item from a menu, or enters data into a text box, one or more events are triggered. You write scripts that specify the processing that should happen when events are triggered.

Windows, controls, and other application components you create with PowerBuilder each have a set of predefined events. For example, each button has a Clicked event associated with it and each text box has a Modified event. Most of the time, the predefined events are all you need. However, in some situations, you may want to define your own events.

PowerScript language

You write scripts using PowerScript, the PowerBuilder language. Scripts consist of PowerScript commands, functions, and statements that perform processing in response to an event.

For example, the script for a button's Clicked event might retrieve and display information from the database; the script for a text box's Modified event might evaluate the data and perform processing based on the data.

The execution of an event script can also cause other events to be triggered. For example, the script for a Clicked event in a button might open another window, triggering the Open event in that window.

PowerScript functions

PowerScript provides a rich assortment of built-in functions that can act on the various components of your application. For example, there is a function to open a window, a function to close a window, a function to enable a button, a function to update the database, and so on.

You can also build your own functions to define processing unique to your application.

Object-oriented programming with PowerBuilder

Each menu or window you create with PowerBuilder is a self-contained module called an object. The basic building blocks of a PowerBuilder application are the objects you create. Each object contains the particular characteristics and behaviors (properties, events, and functions) that are appropriate to it. By taking advantage of object-oriented programming techniques such as encapsulation, inheritance, and polymorphism, you can get the most out of each object you create, making your work more reusable, extensible, and powerful.

Multitier applications

PowerBuilder lets you build applications that run in a distributed computing environment. A multitier application lets you:

  • Centralize business logic on servers, such as JBoss, WebLogic, WebSphere, or COM+

  • Partition application functions between the client and the server, thereby reducing the client workload

  • Build scalable applications that are easy to maintain

For information about multitier applications, see Developing Distributed Applications in Application Techniques.

Database connectivity

PowerBuilder provides easy access to corporate information stored in a wide variety of databases. Data can be accessed through the PowerBuilder ODBC or JDBC interfaces, through a middle-tier data access server like the SAP DirectCONNECT server, or through a native or direct connection to a database.

For information on database connectivity, see Working with Database Connections in Connecting to Your Database.

Online Help and documentation

PowerBuilder Help can be accessed using Help buttons and menu items, or by selecting the F1 key from anywhere in PowerBuilder. There are jumps in several places from the Help to books in HTML format. Manuals are also available on the Appeon website.

The PowerBuilder environment

Workspaces and targets

In PowerBuilder, you work with one or more targets in a workspace. You can add as many targets to the workspace as you want, open and edit objects in multiple targets, and build and deploy multiple targets at once.

A PowerBuilder target can be one of several types:

  • Application target

    A client/server or multitier executable application.

  • .NET target (obsolete)

    A .NET target that you can use to deploy nonvisual custom class components as .NET assemblies or Web services.

The first lesson in the tutorial shows you how to create a workspace and an Application target. Later you learn how to create .NET targets.

The development environment

When you start PowerBuilder, it opens in a window that contains a menu bar and the PowerBar at the top, and the System Tree and Clip windows on the left.

System Tree

The System Tree window can serve as the hub of your development activities. You use it to open, run, debug, and build your targets, and for drag-and-drop programming.

Clip window

The Clip window lets you store code fragments that you use frequently.

Output window

The output of a variety of operations (migration, builds, deployment, project execution, object saves, and searches) displays in an Output window at the bottom of the main window. The Output window opens automatically when output information is generated, but you can open the Output window at any time by clicking the Output window toolbar button.

Painters

Once you have created a workspace and a PowerScript target, you build the components of the target using painters. Painters provide an assortment of tools for enhancing and fine tuning the objects in a target.

PowerBuilder provides a painter for each type of object you build. For example, you build a window in the Window painter. There you define the properties of the window and add controls, such as buttons and text boxes.

Wizards

Wizards simplify the creation of applications, objects, components, websites, and Web pages.

Design-time controls

Design-time controls (DTCs) create basic HTML and scripts from information you provide in property sheets. The property sheets display when you drop a DTC on a Web page in the HTML editor.

To-Do List

The To-Do List displays a list of development tasks you need to do for the current target. Entries on the To-Do list can be created automatically by most PowerBuilder wizards. You can also type in entries or import them from a text file and then link them to a task that you want to complete.

Browser

The Browser lets you see all the objects, methods, variables, and structures that are defined for or available to your PowerScript target. Objects in the Browser can be displayed in alphabetic or hierarchical order or filtered by the object name. The Browser displays methods with their complete prototypes (signatures), which include the datatypes of all arguments and return values.

PowerBar

The PowerBar displays when you begin a PowerBuilder session. The PowerBar is the main control point for building PowerBuilder applications. You can use the New, Inherit, or Open buttons on the PowerBar to open all of the PowerBuilder painters. From the PowerBar, you can also open the Browser, debug or run the current application, and build and deploy the workspace.

PainterBar

When you open a painter or editor, PowerBuilder displays a new window that has a workspace in which you design the object you are building. PowerBuilder also displays one or more PainterBars with buttons that provide easy access to the tools available in the painter or editor. For example, here is the PainterBar for the DataWindow painter.

StyleBar

The StyleBar displays when you open any painter that can contain text controls, such as the Window painter. Using buttons on the StyleBar, you can modify text properties such as the font and point size.

PowerTips

When you leave the mouse pointer over a button for a second or two, PowerBuilder can display a brief description of the button (a PowerTip). The ability to display PowerTips is toggled on and off by selecting the Show PowerTips menu item in any toolbar pop-up menu.

You can also include brief descriptive texts on all toolbar buttons by selecting ShowText from any toolbar pop-up menu.

Customizing the environment

In addition to displaying text in toolbar buttons, you can move the toolbars around, add new toolbars, and customize existing ones. You can add buttons for opening painters and performing other activities.

You can also rearrange the System Tree, Clip, and Output views, set up custom layouts for each painter, choose whether PowerBuilder opens your last workspace at start-up with or without painters and editors open, customize shortcut keys, and change the colors and fonts used in scripts.

PowerBar buttons

The buttons in the PowerBar give you quick access to the most common PowerBuilder tasks:

Button

Use to

Create new workspace, target, component, or other object, or open a tool.

Inherit from menu, user object, or window.

Open an existing application, DataWindow, function, menu, pipeline, project, query, structure, user object, window, HTML page, HTML frame, style sheet, or script file.

Preview a window or DataWindow object.

Show or hide the System Tree window.

Show or hide the Output window.

Move to the next line in the Output window.

Move to the previous line in the Output window.

Display a list of development tasks you need to do. These can be self entered or entered automatically by PowerBuilder wizards.

View object information (such as object properties or global variables) and copy, export, or print it.

Show or hide the Clip window.

Create and maintain libraries of PowerBuilder objects.

Specify how to connect to a database.

Maintain databases, control user access to databases, and manipulate data in databases.

Edit a file.

Start an incremental build of the workspace.

Start a full build of the workspace.

Deploy the workspace.

When a series of operations is in progress, such as a full deploy of the workspace, skip to the next operation.

Stop a build or deploy operation or series of operations.

Debug the current target.

Select a target and debug it.

Run the current target.

Select a target and run it.

Exit from PowerBuilder.


PowerBuilder objects

The basic building blocks of a PowerScript target are objects:

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: Application life cycle

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:

  • Properties that define the window's appearance and behavior (for example, a window might have a title bar and a Minimize box)

  • Events triggered by user actions

  • Controls placed in the window

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

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.

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:

  • If a column can take only a small number of mutually exclusive values, you can have the data appear as radio buttons in a DataWindow so users know what their choices are.

  • If the data includes phone numbers, salaries, and dates, you can format the display to suit the data.

  • If a column can take numbers only in a specific range, you can specify a simple validation rule for the data. This can spare you from writing code to make sure users enter valid data.

Web DataWindow

This technique is not recommended and is considered to be obsolete. An obsolete feature is no longer eligible for technical support and will no longer be enhanced, although it is still available.

The ability to use this technique has been retained for backward compatibility.

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.

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:

  • Object-level functions are defined for a particular type of window, menu, or other object type and are encapsulated within the object for which they are defined. These are further divided into system functions (functions that are always available for objects of a certain object class) and user-defined functions.

  • Global functions are not encapsulated within another object, but instead are stored as independent objects.

Unlike object-level functions, global functions do not act on particular instances of an object. Instead, they perform general-purpose processing such as mathematical calculations or string handling.

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:

  • Object-level structures are associated with a particular type of object such as a window or menu. These structures can always be used in scripts for the object itself. You can also choose to make the structures accessible from other scripts.

  • Global structures are not associated with any object or type of object in an application. You can declare an instance of the structure and reference it in any script in an application.

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:

  • Visual user objects

    These are reusable controls or sets of controls that have a consistent behavior. For example, a visual user object could consist of several buttons that function as a unit. The buttons could have scripts associated with them that perform standard processing. Once the object is defined, you can use it as often as you need.

  • Nonvisual user objects

    These are reusable processing modules that have no visual component. Standard class user objects inherit events and properties from built-in system objects. You typically use nonvisual objects to define business rules and other processing that acts as a unit.

    For example, you might want to calculate commissions or perform statistical analysis in several applications. To do this, you could define a custom class user object. To use a custom class user object, you create an instance of the object in a script and call its functions.

    Custom class user objects, which define functions and variables, are the foundation of PowerBuilder multitier applications. This is because you typically use nonvisual components for applications that are run on a server.

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.