Welcome!

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

Related Topics: PowerBuilder

PowerBuilder: Article

The 15-Minute PFC Learning Curve

Deploy an application that meets your business needs

For years, people have said that PowerBuilder Foundation Classes (PFC) has a steep learning curve. Drives me crazy. Don't believe it for a minute.

While it's true that there is a lot to learn about PFC, the same can be said of cars, but few of us learn the intricacies of ignition systems before learning to drive. The fact is, there are three things you need to know before building your application with PFC; the rest can be learned later. We'll discuss the basic benefits of starting with a PFC architecture with minimal understanding later, but for those readers with attention issues, let's get started on the 15-minute PFC learning curve.

Setting Up the Application Object
First create an application directory and copy in everything from the PFC folder, but not the subdirectories. Then create an application with either

1.  The New Application Wizard

  • Create the application object and application PBL in the directory you've created.
  • The wizard finishes.
  • Right-click on the new target, select Properties, and add all the PBLs you copied from the PFC folder to the Library Search Path.
  • Create your own application manager by creating an empty descendant of (PfeApSrv.pbl)n_cst_AppManager in your application PBL, naming it something like n_cst_AppMgr_YourAppName.
  • Export (PfcApp.pbl)Generic_Pfc_App and copy its contents to your application object, starting with the global variable, but with the following exception:
    - When declaring the global variable gnv_App (an important magic key in PFC), make it of type n_cst_AppMgr_YourAppName as created above instead of type n_cst_AppManager.
2.  The New Application Template Wizard in PB8 or PB9, or the Wizard downloaded from the PFC-Open Source project (http://pfc.codexchange.sybase.com ) in PB10
  • Create the application object and application PBL in the directory you've created.
  • Select the PFC-based application option when prompted.
  • Add to the application Library List all the PBLs you copied from the PFC folder when prompted.
  • Other options: yada, yada, yada.
  • The wizard finishes.
  • Create your own application manager, by creating an empty descendant of (PfeApSrv.pbl)n_cst_AppManager in your application PBL, naming it something like n_cst_AppMgr_YourAppName.
  • Change the generated global variable declaration for gnv_app from n_cst_AppManager to n_cst_AppMgr_YourAppName.
After creating the application object with either of these methods, proceed with the following steps:
  • In the application object, go into Additional Properties, Variable Types. The message object should already be set to n_Msg and the transaction object to n_Tr. Change the error object to n_Err, the dynamic description area (SQLDA) to n_Dda, and the dynamic staging area (SQLSA) to n_Dsa.
  • Remove PfcApp.pbl from your library list and application directory (it was only there for the application model used in the New Application Wizard technique).
  • When you think you want to add code to the application object, instead add it to the corresponding event in your application manager. For example, one of the first things you'll want to do is add an Open(<window>) line to the pfc_Open event of your application manager, not the Open event of your application.
Inherit Everything from Objects in the PFE Layer

1.  Whenever you create a new object, find a PFE object (Pfe*.pbl) to inherit it from.

  • Windows: Inherit from windows in PfeMain.pbl (w_Main, w_Sheet, w_Frame, w_Response, w_Child, w_Popup), but never from w_Master.
  • Custom Classes: If you don't know of a closer class, inherit from n_Base in PfeMain.pbl.
  • Custom Visual: If you don't know of a closer class, inherit from u_Base in PfeMain.pbl.
  • Standard Class/Standard Visual: Inherit from the appropriate class in PfeMain.pbl (the comments identify the class of each object if you can't discern this from the naming convention).
Structures can't be inherited, but consider a descendant of n_BaseAttrib with instance variables instead of structure elements. These can be used instead of structures pretty much everywhere structures can be used except external function calls, and hold the opportunity for extension through their object-oriented characteristics.

Global functions can't be inherited, but consider grouping (encapsulating) functions of a similar type in an autoinstantiate custom class. Again, it gives you opportunities such as function overloading or overriding if the functional group is ever brought to another application.

More Stories By Terry Voth

Terry Voth, an independent consultant, has worked with PowerBuilder for over 10 years, and in the computer industry for over 15 years. He has extensive experience in both the public and private sectors, primarily in Ontario, Canada.

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.