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.
To establish a server automation session with your user object, you need code for these steps.
Declare an OLEObject variable for your user object:
OLEObject ole_analyze
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
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:
Open the User Object painter and create a standard class user object inherited from OLEObject.
Write scripts for the Error and ExternalException events.
Use the name of the new class instead of OLEObject in the declaration:
uo_oleobject ole_analyze
Similar code in Visual Basic connects to your registered object.
Declare an object variable for your user object:
Dim ole_analyze As Object
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
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)