CreateObject function
Description
Creates an instance of a PowerBuilder class in a PowerBuilder.Application OLE
server session.
Controls
PowerBuilder.Application (automation server)
Syntax
1 |
{ <i>automationobject</i>.} <b>CreateObject</b> ( <i>classname</i> ) |
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 |
Return Values
OLEObject. Returns a reference to the instantiated object,
which is valid for automation. If the object couldn’t be
created, CreateObject returns NULL.
Usage
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.
Examples
This example is a PowerBuilder script that starts the PowerBuilder.Application server
and creates an object that is contained in MYLIBRARY.DLL. If it
is successful, it 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:
1 |
OLEObject PBObject, PBNVObject |
1 |
long ll_status |
1 |
double ld_result |
1 |
1 |
PBObject = CREATE OLEObject |
1 |
ll_status = PBObject.ConnectToNewObject & |
1 |
("PowerBuilder.Application") |
1 |
IF ll_status = 0 THEN |
1 |
// Handle the error |
1 |
ELSE |
1 |
PBObject.LibraryList = "c:myapplmylibrary.dll" |
1 |
PBObject.MachineCode = TRUE |
1 |
1 |
PBNVObject = CREATE OLEObject |
1 |
1 |
PBNVObject = & |
1 |
PBObject.<i>CreateObject</i> ("nvo_myobject") |
1 |
IF IsNull(PBNVObject) THEN |
1 |
// Handle the error |
1 |
ELSE |
1 |
ll_status = PBNVObject.uf_calc & |
1 |
(12, 14, REF result) |
1 |
END IF |
1 |
1 |
DESTROY PBNVObject |
1 |
PBObject.DisconnectObject( ) |
1 |
END IF |
1 |
1 |
DESTROY PBObject |
This example is a Visual Basic script that does the same tasks
as the PowerBuilder script above:
1 |
Dim PBObject as object |
1 |
Dim PBNVObject as object |
1 |
Dim status as long |
1 |
Dim result as double |
1 |
1 |
Set PBObject = _ |
1 |
CreateObject("PowerBuilder.Application") |
1 |
If PBObject is nothing then |
1 |
REM handle the error |
1 |
Else |
1 |
PBObject.LibraryList = "c:myapplmylibrary.dll" |
1 |
Set PBNVObject = _ |
1 |
PBObject.<i>CreateObject</i> ("nvo_myobject") |
1 |
If PBNVObject is nothing then |
1 |
REM handle the error |
1 |
Else |
1 |
status = PBNVObject.uf_calc(12, 14, REF result) |
1 |
Set PBNVObject = nothing |
1 |
End if |
1 |
1 |
Set PBObject = nothing |
1 |
End if |
See Also
- ConnectToNewObject