Writing client code that accesses the user object

The client code for accessing a registered user object is simpler than the code for accessing PowerBuilder.Application. The library list and machine code properties are already determined and stored in the registry. All you need to do is connect to the object and use automation to access its properties and methods.

PowerBuilder as client

To establish a server automation session with your user object, you need code for these steps.

  1. Declare an OLEObject variable for your user object:

    OLEObject ole_analyze
    
  2. Connect to your object using its programmatic identifier (ProgID) and check that the connection was established. A status of 0 indicates success:

    ole_analyze = CREATE OLEObject
    
    li_status = ole_analyze.ConnectToNewObject &
       ("MyCompany.Analyze")
    
    IF li_status < 0 THEN
    
       MessageBox("No Server", &
    
          "Can't connect to MyCompany.Analyze.")
    
       RETURN
    
    END IF
    
  3. Access functions or properties of the object using automation syntax:

    ld_avg = ole_analyze.uof_average()
    
    ole_analyze.Projection = TRUE
    
    li_status = ole_analyze.uof_RTFreport(REF ls_rpt)
    

If you want to handle errors in the OLEObject ExternalException and Error events, use a user object inherited from OLEObject instead of declaring an OLEObject variable:

  1. Open the User Object painter and create a standard class user object inherited from OLEObject.

  2. Write scripts for the Error and ExternalException events.

  3. Use the name of the new class instead of OLEObject in the declaration:

    uo_oleobject ole_analyze
    

Visual Basic as client

Similar code in Visual Basic connects to your registered object.

  1. Declare an object variable for your user object:

    Dim ole_analyze As Object
    
  2. Connect to your object using its programmatic identifier (ProgID) and check that the connection was established:

    Set ole_analyze = CreateObject("MyCompany.Analyze")
    
    If ole_analyze Is Nothing Then
    
       REM Handle the error
    
    End If
    
  3. Access functions or properties of the object using automation syntax:

    ld_avg = ole_analyze.uof_average()
    
    ole_analyze.Projection = TRUE
    
    li_status = ole_analyze.uof_RTFreport(REF ls_rpt)