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

Tips and Tricks: Getting the Most from PFC

  • When coding response windows, place your default functionality in the pfc_apply event and call pfc_apply from the pfc_default event.
  • In an MDI application, add this code to the open event of your application object to force a single toolbar:

//Force a single toolbar
this.toolbarframetitle = <some text>
this.toolbarsheettitle = <some text>

  • Add PFC user objects to the PainterBar. This tip is from the Sybase Web site. Search the site for "44589" and you'll find an article entitled "Streamlining PFC Development Tip."
  • Use the DataWindow Properties Service to copy and paste code for DataWindow services. When you enable a service on the Properties dialog, the button marked "Property" becomes enabled. Click on this button to view a window where you can specify individual properties for the service. The "General" tab of this window differs from service to service, but always presents an interface that allows you to manipulate the way the selected service acts. Once you have configured the service, select the "Syntax" tab. The Syntax tab displays the code necessary to implement the service, and allows you to copy the code so that you can paste it into your application.
  • Add your most often used code snippets to PowerBuilder's clip window. This is a very powerful way to speed up your development.
A Need for Speed
Here are a few ideas to help you build efficient, well-performing applications:
  • Bitmaps and images: Be sure to include the PFC bitmaps and icons in a PBR file. If PowerBuilder needs to search for images across a network path, performance will definitely suffer. When you place the PFC images into a PBR (resource) file, you cause the images to be included as part of the executable.
  • Use a local copy of PFC files: When you're developing, use a copy of the PFC (and PFE) files on your local workstation. Use Source Control to manage updates to the PFE files. Of course, the PFC files should not change.
  • Build often: As often as is practical, perform a full build of your application. This will help minimize incremental rebuilds when you open or save objects.
  • Use DataWindow caching: Cache repetitive data using the DataWindow caching service.
  • PFC and source control: Don't put the PFC libraries under source control. The PFE libraries and all other application libraries should definitely be under source control though.
Debugging PFC
Avoiding the Activate Event

One of the most frustrating aspects of using the PowerBuilder debugger with PFC is the debugger's insistence on stopping in the activate event of your windows when you're stepping through program code. You can easily skip over the activate event by clicking the "Step Out" button on the toolbar. But if even this becomes too cumbersome, there is a way out. Create a debug version of pfc_w_master. Copy pfc_w_master into a PBL that is ahead of pfcmain.pbl in the library list, then erase all of the code in the activate event. Note that this will make it impossible for you to use the MRU (Most Recently Used) service, since the code to use the MRU service is in the activate event. You may also need to create debug copies of other windows in the inheritance chain if you have placed code in the activate event. Be sure to remove your debugging versions of objects before you release your product.

PFC Debug Log
Make use of the debug log. PFC includes a debug service, n_cst_debug. Among other capabilities, the debug service lets you use and display a debug log. Instantiate the debug service at the application manager level:


Then you can log a message by using the debug service's of_Message function:

gnv_app.inv_debug.of_Message("Show this in the debug log")

At any point in your program you can display the debug message log using the of_OpenLog function. Call it with a value of TRUE to open the window, and a value of FALSE to close the window:


Of course, you can add icons to your status bar (using the status bar service) to open and close the debug log window.

What's Changed in the PFC
Since its introduction with PowerBuilder version 5, PFC has undergone a number of changes - some drastic, some less so. The most sweeping change was between PowerBuilder version 5 and version 6. Other versions saw more changes, as well as some bug fixes and patches. Each version of PowerBuilder includes a readme file for PFC. The readme file lists all of the details for the changes.

Changes in PFC as of PowerBuilder 6
With the introduction of PowerBuilder version 6, PFC was changed to enhance usability and consistency. Obsolete objects from PowerBuilder 5 were moved into a library called PFCOLD.PBL and two new libraries were added. The new libraries were PFCUTIL.PBL and PFEUTIL.PBL. These new libraries are home to the debug service, the DataWindow properties service, and the SQLSpy service.

A number of new objects were added to the existing libraries, including:

  • (pfc_)n_cst_color: Provides a set of color constants.
  • Attribute objects: Nonvisual objects that contain attributes used for various services.
  • Service-based TreeView and ListView: These new objects use services to populate their items and react to user actions. The objects are (pfc_)n_cst_tvsrv and (pfc_)n_cst_lvsrv. The necessary service objects were also added.
    -DataStore versions of DataWindow services.
    -Additional PFC standard user objects based on PowerBuilder controls.
    -A dropdown calculator object was added.
    -A dropdown calendar was added.
    -A progress bar object was added.
    -A splitbar object was added.
In version 6, syntax and object methods were changed to provide a more consistent user interface:
  • The function of_register was added to many objects in place of functions with varying, unrelated names.
  • Prefixes were removed from the names of constants, and constants were specified in all caps.
  • of_setUpdateStyle replaced individual "set" functions for different update styles in the Linkage service. More update styles were added.
  • of_setStyle replaced multiple link-style functions in the Linkage service.
  • of_setmaster replaced of_linkTo in the Linkage service.
  • pfc_populateDDDW event replaced pfc_retrieveDDDW event in u_dw.
  • DataWindow Properties service replaced the DWDebugger.
Changes in PFC as of PowerBuilder 7
The big change in PFC for PowerBuilder 7 was a change in the way object structures were used. In PowerBuilder 7, object structures declared as instance variables must be explicitly declared as PRIVATE or a warning will be generated. To preserve extensibility of these object structures in PFC, the structures were changed to nonvisual attribute classes. To accommodate this change, each attribute object has a corresponding object in the extension (PFE) layer and each reference to an object structure (os_<structure>) was changed to refer to the new PFE-layer attribute object.

PowerBuilder 7 also marked the use of the native Microsoft TreeView and ListView objects. Some fixes were incorporated in PFC for this change, but some issues remained until PowerBuilder 8.0.1 became available.

The balance of the changes to PFC 7 were bug fixes.

Changes in PFC as of PowerBuilder 8
PowerBuilder 8 incorporated only a few but significant changes. The pfccom32.dll dynamic link library was dropped and its functionality was moved into the PowerBuilder VM. This library contained only one routine, pfc_printdlg, which calls the Windows Common Print dialog. The return code representing a user cancel action was changed from -1 in previous versions to 0 in PowerBuilder 8.

Microsoft changed its implementation of several controls such that the right-mouse button operates slightly differently. This means that the rbuttonup event, used previously to invoke RMB popup-menus, is no longer a reliable way to initiate these events. A new event, contextmenu, mapped to pbm_contextmenu, has been added to invoke these popup menus, and the PFC objects that utilize popup menus have been changed accordingly. Any code that a developer added to extend the rbuttonup menu should be evaluated in light of these changes.

PFC 8 also included a number of bug fixes, detailed in the readme file.

Changes in PFC as of PowerBuilder 9
What's new in PFC for PowerBuilder 9? The news for PowerBuilder 9 is that there are no changes at all to PFC.

PFC Resources
Of course, Sybase's Web site (www.sybase.com) is an excellent source of information, white papers, release notes, sample code, and online documentation.

It is natural that because PFC is so extendable, you'll find extensions available. There are several Web sites that provide information, discussion groups, additional white papers, and user-written extensions for PFC. Two such sites are www.pfcGuide.com and www.pfcCheatSheet.com.

PFC as a Distributed Framework
In a word - not! PFC is an excellent and powerful client/server foundation library. It's not suited for distributed development. Why? First, it's too tightly coupled. In most cases, to use any of PFC's capabilities, you're required to include the entirety of PFC. This is not a burden with an application, but would result in huge distributed components that would hamper performance and scalability of a distributed system. Second, most of PFC's benefits are visual in nature. They either enhance the visual aspects of the user interface or respond to user input (such as the Linkage service).

The PowerBuilder Foundation Classes (PFC) provide a rich set of objects and services for the PowerBuilder developer. PFC gives you expanded user interface capabilities, including flexible and powerful menu processing, window services, DataWindow services (such as the linkage service), and application services. By using the PFC and the concepts learned in this article you'll be able to provide more usability and utility to your applications

.  .  .

This article is based on PowerBuilder 9: Advanced Client/Server Development by various authors (ISBN 0672325004), published by Sams Publishing. Also look for PowerBuilder 9 Internet and Distributed Application Development.

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.