Using the extension in PowerBuilder

To use the PowerBuilder native class in a PowerBuilder application, import the object descriptions in the PBX file into a library in your application.

StepsTo import the extension into an application:

  1. Copy the PBX (or DLL) file to a directory on your application’s path.

  2. In PowerBuilder, create a new workspace.

  3. On the Target page of the New dialog box, select the Application icon to create a new target, library, and application object.

  4. In the System Tree, expand the new target, right-click the library, and select Import PB Extension from the pop-up menu.

    Import PB Extension displays the Select PB Extensions Files dialog box.
  5. Navigate to the location of the pbadd.pbx file and click Open.

StepsTo invoke the f_add function in PowerBuilder:

  1. Create a new window called w_add, and add three single-line edit boxes and a command button to it.

  2. Declare an instance variable called mypbadd for the pbadd native class, and then add this script to the button’s Clicked event:

    TRY
       mypbadd = CREATE pbadd
       sle_3.text = string (mypbadd.f_add( &
          integer(sle_1.text), integer(sle_2.text)))
    CATCH (runtimeerror re)
       MessageBox("Error", &
          "pbadd native class could not be created: " + &
          re.getmessage() )
    END TRY
    

    The pbadd class displays in the System Tree. As shown in the following screen shot, you can expand its function list:

    The illustration shows the System Tree at left. Expanded is a p b d called p b n i add dot p b d. Indented under the p b d is the class p b add, which is expanded to show folders for Properties, Events, and Functions. The Functions folder is epxanded to show a list of functions including the highlighted function f _ add ( integer a , integer b ) returns integer. At top right a screen layout displays two blank rectangles, a plus sign, and a third blank rectangle. At bottom right, the clicked tab page displays the script for c b _ 1.
  3. Add open(w_add)to the application’s Open event.

  4. Run the application.

    The application runs just as it would if you had created a custom class user object in PowerBuilder with an f_add function. If PowerBuilder cannot find pbadd.pbx, the runtime error in the Clicked event script will be triggered and caught. Put pbadd.pbx in the same directory as the executable or the PowerBuilder runtime DLLs to make sure it can be found.