Using Sample Applications

About this chapter

This chapter describes how to use PowerBuilder sample applications.

About the sample applications

PowerBuilder provides sample applications with source code so you can learn and reuse the techniques used in the samples.

These samples are contributed by Appeon employees and users and are updated frequently. They include standalone applications that illustrate specific features of PowerBuilder, including features such as using Web services, and writing visual and nonvisual extensions using the PowerBuilder Native Interface. Most samples include a readme document that explains which features a sample demonstrates and how to download and use it.

Installing the sample applications

If you install PowerBuilder using the PowerBuilder Installer (an online setup program), the sample applications are automatically installed. If you install PowerBuilder using the downloaded installation package (an offline setup program), to install the samples from the offline setup program, select Code Examples from the list of components; to install Code Examples applications, select Example Application.

The setup program installs all samples in Code Examples subdirectories. Most Code Examples applications use a sample SQL Anywhere database called PB Demo DB. The Code Examples subdirectories and PB Demo DB databases are installed in the C:\Users\Public\Public Documents\Appeon\PowerBuilder 19.0 directory on Windows 8.1/10.

If you cannot find the Code Examples directory or the PBDEMO2019R3.DB file, the sample applications and the database may not have been installed.

Opening the sample applications

To open a sample application, select Programs>Appeon>PowerBuilder 2019 R3>Code Samples from the Start menu, then select the sample application that you want to open.

The next section contains a procedure that steps you through opening and running the Code Examples application.

Using the Code Examples application

You run the Code Examples application from the development environment.

To run the Code Examples application:

  1. Select File > New from the menu bar, select Workspace from the Workspace tab, and click OK.

  2. Navigate to the C:\Users\Public\Documents\Appeon\PowerBuilder 19.0\Code Examples\Example App folder, type a name for the workspace, and click Save.

  3. Select Add Target from the pop-up menu for the workspace you just created, navigate to the C:\Users\Public\Documents\Appeon\PowerBuilder 19.0\Code Examples\Example App folder, select the PB Examples target file, and click Open.

    If you expand the target, you will see that the PBL that contains the application and all its supporting PBLs have been added to the workspace.

  4. Click the Run button on the PowerBar.

Browsing the examples

When the Code Examples application opens, the left pane contains an expandable tree view listing the categories of examples available. Some examples appear in more than one category. For example, the Business Class example is listed under Inheritance and User Objects. If you are looking for examples showing how to work with a specific feature, such as DataStores or DataWindows, expand that category and look at the example names.

When you select an example in the left pane, a description of the example and the techniques it demonstrates displays on the right:

Finding examples

If you are looking for ways to work with a specific PowerBuilder object class or feature, you can use the categories in the Examples pane and the descriptions to locate examples. If you are looking for examples using a specific event, function, or user-defined object, use the Search pane.

To search for a function, event, or object:

  1. Click the Search tab in the Code Examples main window.

  2. Select a radio button in the Search On group box.

  3. Select the item you want in the drop-down list and click Perform Search.

    The names of all the examples that use the function, event, or object you searched for display:

Running and examining examples

Once you have located an example that performs some processing you want to learn about, you can run it to examine how it works and look at the code (and copy it if you want to).

Running an example

To run the highlighted example, double-click it or click Run!. You can get Help on how to use the example and what it does by clicking the Help button on the example's main window.

Examining the code

To see all the objects used in an example, click the Related Objects tab on the right pane and click the plus signs to expand items:

Double-click the icon for a script or function to examine it.

Using examples in the development environment

Running the Code Examples application and looking at the code for an example gives you a lot of information, but if you open objects in the examples in the development environment, you can examine them in more depth.

For example, you can open any object in a painter, examine the inheritance hierarchy in the Browser, and step through an example in the Debugger. You can even copy objects to your own application in the Library painter or copy code fragments to the Script view.

The libraries in the Code Examples application are organized by object type. For example, pbexamd1.pbl and pbexamd2.pbl contain DataWindow objects. This makes it easy to find the objects that are referenced as examples later in this book. If you expand the sample libraries in the List view in the Library painter, the comments tell you what each object is used for.