Syntax 2 For creating a component instance on the current server
Description
Creates an instance of a component running on the current EAServer or COM+ server.
This function is called from within a component instance running
on EAServer or COM+.
Controls
TransactionServer objects
Syntax
|
1 |
<span>transactionserver</span>.<span>CreateInstance</span> (<span>objectvariable</span> {, <span>classname</span> } ) |
|
Argument |
Description |
|---|---|
|
transactionserver |
Reference to the TransactionServer service |
|
objectvariable |
A global, instance, or local variable |
|
classname (optional) |
A string whose value is the name of the For EAServer components, For COM+ components, you can optionally prepend a |
Return Values
Long. Returns 0 if it succeeds and one
of the following values if an error occurs:
-
50 Distributed
service error -
52 Distributed communications error
-
53 Requested server not active
-
54 Server not accepting requests
-
55 Request terminated abnormally
-
56 Response to request incomplete
-
57 Not connected
-
62 Server busy
Usage
The CreateInstance function on the TransactionServer
context object allows you to access other EAServer or
COM+ components running on the current server. The created
instance inherits all the transaction and security attributes of
the current object.
On EAServer, the TransactionServer CreateInstance method
invokes the EAServer name
service to create proxies. Proxies for remote components might be
returned by the name service rather than an instance that is running locally.
To guarantee that a locally installed instance is used, specify
the component name as “local:package/component“,
where package is the package name and component is
the component name. The call fails if the component is not installed
in the same server.
The CreateInstance function on the TransactionServer
context object uses the same user and password information that
applies to the component from which it is called.
Before you can use the transaction context service, you need
to declare a variable of type TransactionServer and call the GetContextService function
to create an instance of the service.
Examples
The following statements show how an EAServer component might instantiate another
component in the same server and call one of its methods:
|
1 |
Integer rc |
|
1 |
rc = this.GetContextService("TransactionServer", & |
|
1 |
ts) |
|
1 |
IF rc <> 1 THEN |
|
1 |
// handle the error |
|
1 |
END IF |
|
1 |
rc = this.<span>CreateInstance</span>(mycomp2, & |
|
1 |
"mypackage/nvo_comp2") |
|
1 |
|
1 |
IF IsValid(mycomp2) = FALSE THEN |
|
1 |
// handle the error |
|
1 |
END IF |
|
1 |
mycomp2.method1() |
This example shows the syntax for creating an instance
of a COM component:
|
1 |
Integer rc<br>OleObject lole<br>TransactionServer lts<br> <br>lole = create OleObject<br>rc = this.GetContextService("TransactionServer", lts)<br>IF rc <> 1 THEN<br>   return "Error from GetContextService " + String (rc)<br>END IF<br> <br>// PBCOM is the ProgID, n_genapp is the class name<br>rc = lts.<span>CreateInstance</span>(lole, "PBCOM.n_genapp")<br> <br>IF rc <> 0 THEN<br>   return "Error from CreateInstance " + String (rc)<br>END IF<br>iole.my_func () |