ConnectToNewObject PowerScript function
Description
Creates a new object in the specified server application and
associates it with a PowerBuilder OLEObject variable. ConnectToNewObject starts
the server application if necessary.
Controls
OLEObject objects, OLETxnObject objects
Syntax
|
1 |
<span>oleobject</span>.<span>ConnectToNewObject </span>( <span>classname</span> ) |
|
Argument |
Description |
|---|---|
|
oleobject |
The name of an OLEObject variable that |
|
classname |
A string whose value is a programmatic |
Return Values
Integer. Returns 0 if it succeeds and
one of the following negative values if an error occurs:
-
-1 Invalid Call: the
argument is the Object property of a control -
-2 Class name not found
-
-3 Object could not be created
-
-4 Could not connect to object
-
-9 Other error
-
-15 COM+ is not loaded on this
computer -
-16 Invalid Call: this function not applicable
If any argument’s value is null, ConnectToNewObject returns null.
Usage
The OLEObject variable can be used for automation, in which
the PowerBuilder application asks the server application to manipulate
the OLE object programmatically. It can also be used to connect
to a COM object that is registered on a local or remote computer
or that is installed in COM+.
The OLETxnObject variable is used to provide COM+ transaction
control to PowerBuilder clients. Calling ConnectToNewObject with
an OLETxnObject variable creates a new object instance within the
transaction context associated with the variable. If COM+ is
not loaded on the client computer, the ConnectToNewObject call
fails. Use SetAbort to abort the transaction
or SetComplete to complete it if all other participants
in the transaction concur.
For more information about automation and connecting to COM
objects, see ConnectToObject.
Deprecated support for COM and COM+ components
COM and COM+ are deprecated technologies and might
not be supported in future releases of PowerBuilder.
Examples
This example creates an OLEObject variable and calls ConnectToNewObject to create
a new Excel object and connect to it:
|
1 |
integer result |
|
1 |
OLEObject myoleobject |
|
1 |
myoleobject = CREATE OLEObject |
|
1 |
result = myoleobject.<span>ConnectToNewObject</span>( & |
|
1 |
"excel.application") |
This example creates an OLETxnObject variable and
calls ConnectToNewObject to create and connect
to a new instance of a PowerBuilder COM object on a COM+ server:
|
1 |
OLETxnObject EmpObj |
|
1 |
Integer li_rc |
|
1 |
EmpObj = CREATE OLETxnObject |
|
1 |
li_rc = EmpObj.<span>ConnectToNewObject</span>("PB125COM.employee") |
|
1 |
IF li_rc < 0 THEN |
|
1 |
DESTROY EmpObj |
|
1 |
MessageBox("Connecting to COM Object Failed", & |
|
1 |
"Error: " + String(li_rc)) |
|
1 |
Return |
|
1 |
END IF |
|
1 |
|
1 |
// Perform some work with the COM object |
|
1 |
... |
|
1 |
// If the work completed successfully, commit |
|
1 |
// the transaction and disconnect the object |
|
1 |
EmpObj.SetComplete() |
|
1 |
EmpObj.DisconnectObject() |