ConnectToNewObject

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.

Applies to

OLEObject objects, OLETxnObject objects

Syntax

oleobject.ConnectToNewObject ( classname )

Argument

Description

oleobject

The name of an OLEObject variable that you want to connect to an automation server or COM object. You cannot specify an OLEObject that is the Object property of an OLE control.

classname

A string whose value is a programmatic identifier or class ID that identifies an automation server or COM server.

Returns

Integer. Returns 0 if it succeeds and one of the following negative values if an error occurs:

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.

NoteDeprecated support for COM and COM+ components Starting with version 11.5, you can no longer deploy COM or COM+ components from the PowerBuilder IDE. However, you can continue to connect to existing PowerBuilder COM and COM+ components from PowerBuilder applications.

Examples

Example 1

This example creates an OLEObject variable and calls ConnectToNewObject to create a new Excel object and connect to it:

integer result

OLEObject myoleobject

myoleobject = CREATE OLEObject

result = myoleobject.ConnectToNewObject( &

    "excel.application")

Example 2

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:

OLETxnObject EmpObj

Integer li_rc

EmpObj = CREATE OLETxnObject

li_rc = EmpObj.ConnectToNewObject("PB110COM.employee")

IF li_rc < 0 THEN

    DESTROY EmpObj

    MessageBox("Connecting to COM Object Failed",  &

      "Error: " + String(li_rc))

   Return

END IF


// Perform some work with the COM object

...

// If the work completed successfully, commit

// the transaction and disconnect the object

EmpObj.SetComplete()

EmpObj.DisconnectObject()

See also