Creates an instance of a PowerBuilder class in a PowerBuilder.Application OLE server session.
PowerBuilder.Application (automation server)
{ automationobject.} CreateObject ( classname )
Argument |
Description |
---|---|
automationobject |
When PowerBuilder is the OLE client, the name of the OLEObject instantiated with the PowerBuilder.Application automation server. For other clients, use syntax appropriate for calling a function belonging to an automation object. |
classname |
A string specifying the name of the class you want to create. The class must be defined in one of the libraries specified in the PowerBuilder.Application LibraryList property. |
OLEObject. Returns a reference to the instantiated object, which is valid for automation. If the object could not be created, CreateObject returns NULL.
If the OLE client is Visual Basic, you can test for the keyword nothing to see if CreateObject succeeded.
If the object’s executable type does not correspond to the value of the MachineCode property, then CreateObject returns NULL. All the objects created for one PowerBuilder.Application session must have the same executable type (either Pcode or compiled machine code). When you create more than one object in a single PowerBuilder.Application session, those objects can be passed as function arguments or returned as results.
You do not need to use the CREATE statement for the OLEObject variable before calling the CreateObject function.
This example is a PowerBuilder script that starts the PowerBuilder.Application server and creates an object that is contained in MYLIBRARY.DLL. If the object is created successfully, the script calls the function uf_calc, which returns a Long as a status code and passes back the result of the calculation in the variable ld_result:
OLEObject PBObject, PBNVObject
long ll_status
double ld_result
PBObject = CREATE OLEObject
ll_status = PBObject.ConnectToNewObject &
("PowerBuilder.Application")
IF ll_status = 0 THEN
// Handle the error
ELSE
PBObject.LibraryList = "c:\myappl\mylibrary.dll"
PBObject.MachineCode = TRUE
PBNVObject = CREATE OLEObject
PBNVObject = &
PBObject.CreateObject("nvo_myobject")
IF IsNull(PBNVObject) THEN
// Handle the error
ELSE
ll_status = PBNVObject.uf_calc &
(12, 14, REF result)
END IF DESTROY PBNVObject
PBObject.DisconnectObject( )
END IF
DESTROY PBObject
This example is a Visual Basic script that does the same tasks as the PowerBuilder script above:
Dim PBObject as object
Dim PBNVObject as object
Dim status as long
Dim result as double
Set PBObject = _
CreateObject("PowerBuilder.Application")
If PBObject is nothing then
REM handle the error
Else
PBObject.LibraryList = “c:\myappl\mylibrary.dll”
Set PBNVObject = _
PBObject.CreateObject(“nvo_myobject”)
If PBNVObject is nothing then
REM handle the error
Else
status = PBNVObject.uf_calc(12, 14, REF result)
Set PBNVObject = nothing
End if
Set PBObject = nothing
End if
ConnectToNewObject