Connecting to a COM server

To access a method associated with a component in the COM server, the PowerBuilder client connects to the component using its programmatic identifier (ProgID) or its class identifier (CLSID).

You can use a tool such as OLEVIEW or the OLE tab in the PowerBuilder Browser to view the Program ID or CLSID and methods of registered COM objects.

To establish a connection to the COM server, you need to execute the PowerScript statements required to perform these operations:

  1. Declare a variable of type OLEObject and use the Create statement to instantiate it.

  2. Connect to the object using its Program ID or CLSID.

  3. Check that the connection was established.

Example

The following script instantiates the EmpObj OLEObject object, connects to the COM object PBcom.Employee, and checks for errors:

OLEObject EmpObj
Integer li_rc
EmpObj = CREATE OLEObject
li_rc = EmpObj.ConnectToNewObject("PBcom.employee")
IF li_rc < 0 THEN
    DESTROY EmpObj
MessageBox("Connecting to COM Object Failed",  &
   "Error: " + String(li_rc))
Return
END IF