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:
-
Declare a variable of type
OLEObject and use the Create statement to instantiate
it. -
Connect to the object using its Program ID or CLSID.
-
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:
|
1 |
OLEObject EmpObj<br>Integer li_rc<br>EmpObj = CREATE OLEObject<br>li_rc = EmpObj.ConnectToNewObject("PBcom.employee")<br>IF li_rc < 0 THEN<br>    DESTROY EmpObj<br>MessageBox("Connecting to COM Object Failed", &<br>   "Error: " + String(li_rc))<br>Return<br>END IF |