Writing client code that accesses PowerBuilder and user objects

A client application that wants to establish a PowerBuilder.Application session needs code to:

All the steps of the process should be accompanied by error checking because there are any number of reasons why server sessions can fail.

The following steps with code examples illustrate how to do it. The first set of steps shows client code for PowerBuilder. A Visual Basic example follows.

PowerBuilder as a client

To establish a server automation session with PowerBuilder.Application and access objects, you need code for each of these steps:

  1. Declare one OLEObject variable for PowerBuilder.Application. Declare additional OLEObject variables for each object you will create.

    OLEObject ole_pba, ole_analyze
    

    If you want to handle errors in the OLEObject ExternalException and Error events, use a user object inherited from OLEObject instead.

  2. Start the automation server and check that the connection was established. A status of 0 indicates success.

    ole_pba = CREATE OLEObject
    
    li_status = ole_pba.ConnectToNewObject &
       ("PowerBuilder.Application")
    
    IF li_status < 0 THEN
    
       MessageBox("No Server", &
    
          "Can't connect to PowerBuilder.Application.")
    
       RETURN
    
    END IF
    
  3. Set the properties of PowerBuilder.Application, establishing the libraries you will access. You cannot change these property values after you create objects.

    ole_pba.LibraryList = &
    
       "c:\pbobjs\myobj\serv1.dll;c:\pbobjs\myobj\serv2.dll"
    
    ole_pba.MachineCode = TRUE
    
  4. Create the first object you want to use and check for success. Specify the object’s name as defined in the library:

    ole_analyze = ole_pba.CreateObject("uo_analyze")
    
    IF IsNull(ole_analyze) THEN
    
       MessageBox("No Object", &
    
          "Can't create object uo_analyze.")
    
       RETURN
    
    END IF
    
  5. Access functions or properties of the object using automation syntax. (These properties and methods are hypothetical.)

    ld_avg = ole_analyze.uof_average()
    
    ole_analyze.Projection = TRUE
    
    li_status = ole_analyze.uof_RTFReport(REF ls_rpt)
    
  6. Disconnect from PowerBuilder.Application and destroy the objects when you are done. (Exiting your application also accomplishes this.)

    DESTROY ole_analyze
    
    ole_pba.DisconnectObject()
    
    DESTROY ole_pba
    

Visual Basic version

This example shows typical Visual Basic client code for establishing a server automation session with PowerBuilder.Application. The steps are similar to those for PowerBuilder above.

  1. Declare an object variable for the PowerBuilder.Application. Declare additional object variables for each object you will create.

    Dim ole_pba As Object
    
    Dim ole_analyze As Object
    
  2. Start the automation server and check that the connection was established. A status of 0 indicates success.

    Set ole_pba = CreateObject_
       ("PowerBuilder.Application")
    
    If ole_pba Is Nothing Then
    
       REM Handle the error
    
    End If
    
  3. Set the properties of PowerBuilder.Application, establishing the libraries you will access. You cannot change these property values after you create objects.

    ole_pba.LibraryList = _
    
       "c:\pb\myobj\serv1.dll;c:\pb\myobj\serv2.dll"
    
    ole_pba.MachineCode = TRUE
    
  4. Create the first object you want to use and check for success. You specify the object’s name as defined in the library:

    Set ole_analyze = ole_pba.CreateObject _
    
       ("uo_analyze")
    
    If ole_analyze Is Nothing Then
    
       REM Handle the error
    
    End If
    
  5. Access functions or properties of the object using automation syntax. (These properties and methods are hypothetical.)

    ld_avg = ole_analyze.uof_average()
    
    ole_analyze.Projection = TRUE
    
    li_status = ole_analyze.uof_RTFreport(REF ls_rpt)
    
  6. Destroy the objects. (Exiting the application also accomplishes this.)

    Set ole_analyze = Nothing
    
    Set ole_pba = Nothing
    

For complete information about PowerBuilder.Application functions and properties, see “Runtime automation server reference”.