Welcome!

PowerBuilder Authors: Chris Pollach, Yeshim Deniz, Jayaram Krishnaswamy, Kevin Benedict, Avi Rosenthal

Related Topics: PowerBuilder

PowerBuilder: Article

PFC Quickstart

Provide more usability and utility to your applications Part 2

PowerBuilder includes a powerful set of foundation classes to speed development. These classes are collectively known as the PowerBuilder Foundation Classes, or PFC. In Part 1 (Vol. 11, issue 9) I provided an introduction to PFC and demonstrated how to use it. Part 2 outlines the more recent changes and additions to PFC.

PFC Quickstart
This section contains some scripts that you can paste into your PFE objects to get a jump start on PFC programming.

The Wizsrce Scripts
As you saw in the section on the PFC Start Wizard in Part 1, Sybase has provided a few script files that you can paste into the application manager. You'll find these scripts in the pfcwizsrce folder. You can use these scripts whether or not you use the Wizard to create your PFC application. The Wizsrce scripts enable basic PFC functionality in the application manager. It's worth noting that these scripts are simply text files and can be modified to suit your purposes. The wizsrce scripts are summarized in Table 1.

Where Can You Get Coding Examples?
As anyone who has been programming for a while will tell you, some of the most productive coding you'll do will come from reusing code "borrowed" from other sources. This gives you a head start because you can use known, working code that solves a particular problem. PFC includes a comprehensive sample application that gives thorough examples of coding techniques for PFC objects and services. The PFC Example application is in the folder C:Program FilesSybasePowerBuilder 9.0PFCExamples. Add the target file "PFC Examples.pbt" to your workspace. Perform a full build of this target, then run the application.

The user interface for this application lets you select a given illustration and run that example. As you review each of these mini-applications, take note of any useful or interesting implementations. Then check out the code to find the techniques used to create the effects.

The windows for the examples can be found in the file APPEXAMP.pbl. Find the window that corresponds to the example that you want to examine. When you look at the code, you'll see well-coded working illustrations of PFC techniques. You can copy and paste this code and modify it to suit the purposes of your own PFC applications.

The help file for the PFC Examples application says, "The front end launching utility is probably the best example in the application." The front end launcher presents you with a very rich user interface that uses many PFC techniques:

  • TreeView
  • ListView
  • Split Bar
  • Resize Service
  • MRU Service
  • Debug and SQL Spy Service
  • Status Bar Service
As with any of the examples, you can copy and paste the code from the front end launcher into your own applications, and modify it as necessary. You will find the objects for the front end launcher in the APPEXMFE.PBL file.

Using Common PFC Objects and Services
Use PFC visual user objects much like you would use any standard PowerBuilder object. That is, you simply place the object on your window or user object using the user object button on the Painter Bar. When you write code for these objects you will see additional events that you can place script in.

PFC services are nonvisual objects. These must be created (or instantiated) in order to use them. As you have already seen, you do this by calling a function of the form of_set<service> where <service> represents the service you want to use.

For many services you must supply additional information. In most cases, the service will provide one or more forms of the function of_register. Of_register is used to supply related column names to the linkage service, to configure controls for the resize service, and for many other uses throughout PFC services. There are also a number of functions such as of_setTransObject that you use to supply a value for a single property to a PFC object or service.

In the next few sections you'll see a sampling of a few of the more useful PFC objects and services. This is by no means an exhaustive catalog, but rather an introduction to a select few of PFC's features.

PFC Constants
To make coding easier and your resulting code more readable, PFC includes a number of symbolic constants. You'll find the PFC constants in each of the services or objects that require them. For instance, the Linkage service defines a number of constants, including those that specify the update style. Look in the instance variables for the declarations of the constants:

//- UpdateStyle Constants:
constant integer TOPDOWN =1
constant integer BOTTOMUP =2
constant integer TOPDOWN_BOTTOMUP =3
constant integer BOTTOMUP_TOPDOWN =4
constant integer CUSTOM =101

To use these constants, use the reference variable defined for the service. For example, this statement uses constants defined on the DataWindow's inv_linkage service:

dw_master.inv_linkage.of_setUpdateStyle(dw_master.inv_linkage.TOPDOWN)

Menus
PFC Menus use a feature called the Message Router to notify windows and controls of the user's menu selection. Each menu that is descended from pfc_m_master has a function, of_sendMessage, that is used to initiate the message router with a specific text message. The text message is the name of an event that you want to be executed on a window or control in response to your user's menu selection. For instance, to send a message that the user would like to start a queue, the call to of_sendMessage would look like this:

of_sendMessage("ue_startqueue")

The call to of_sendMessage should be placed in the clicked event of the menu item. Figure 1 shows the path a message takes through the message router.

As you can see, the of_sendMessage function passes the message to the pfc_messageRouter event on the current window where it's processed. The pfc_messageRouter event then tries to trigger the event on (in order) the current window, the current control, the last active DataWindow, and the MDI frame. If no place can be found to trigger the event, the message is ignored. If the message can be processed, no further routing takes place.

PFC also includes four right-mouse button (RMB) menus, shown in Table 2.

The RMB menus do not use the message router. Instead, they use the dynamic keyword to fire an event on the parent control. For instance, the "Cut" selection on m_edit fires an event called pfc_cut on the parent control, if such an event exists. This is the code from the pfc_m_edit clicked event for the m_edititem.m_cut menu item:

idrg_parent.dynamic event pfc_cut()

An event on the PFC controls, pfc_preRMBMenu, allows you to manage menu settings. Pfc_preRMBMenu receives the menu as an argument. To enable or disable a particular menu item, code true or false for the enabled property of that menu item. For example, to disable the "delete" menu item for the DataWindow's RMB menu, code the following in the pfc_preRMBMenu event of the u_dw based DataWindow control:

am_dw.m_table.m_delete.enabled = false

To completely disable the RMB menu for a control, insert the following code into the constructor event of the control:

ib_RMBMenu = FALSE
datawindows (u_dw)

The PFC DataWindow control, u_dw, is one of the most important PFC controls. To use u_dw, just place it on any window as needed. Since it's a user object, you'll use the user object icon on the PowerBuilder Painter Bar to place an instance of u_dw.


More Stories By Millard F. Brown

Millard F. Brown is vice president of Power3, LLC, a company providing consulting and training services for the enterprise. He has beend developing PowerBuilder applications since PowerBuilder 2 and is the co-author of two new PowerBuilder 9 books: PowerBuilder 9: Advanced Client/Server Development and PowerBuilder 9: Internet and Distributed Application Development.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.