Invoking a component method
To invoke a method on most component types, you need to execute
the PowerScript statements required to perform these operations:
-
Use the CreateInstance method
to create an instance of the component. -
Invoke the method.
You use a different technique to invoke EJB component methods.
See “Invoking an EJB component
method”.
Example 1
This script instantiates a component on the server and invokes
a component method. In this example, the CreateInstance method
does not specify a package; therefore, EAServer uses
the default package specified in the Application property of the
Connection object:
1 |
// Global variable:<br>// connection myconnect<br> <br>uo_customer iuo_customer<br>string ls_custid<br>long ll_rc<br> <br>ls_custid = Trim(sle_custid.text)<br>ll_rc = myconnect.CreateInstance(iuo_customer)<br>if ll_rc <> 0 then <br>   MessageBox("CreateInstance failed", ll_rc) |
1 |
   return 999<br>end if<br>if iuo_customer.retrieve_balance(ls_custid) != 1 then<br>    MessageBox("Error", "Retrieve failed!")<br>end if |
Example 2
This script instantiates a component on the server and assigns
the object reference to a variable whose datatype is an ancestor
of the class for the component. The second argument to the CreateInstance function
specifies the class name for the component as well as the EAServer package name:
1 |
// Global variable:<br>// connection myconnect<br> <br>uo_person lnv_object<br>string ls_custid<br>long ll_rc<br> <br>ls_custid = Trim(sle_custid.text)<br>ll_rc = myconnect.CreateInstance(lnv_object, &<br> "PB_pkg_1/uo_customer")<br>if ll_rc <> 0 then <br> MessageBox("CreateInstance failed", ll_rc) |
1 |
return 999<br>end if<br>if iuo_customer.retrieve_balance(ls_custid) != 1 then<br> MessageBox("Error", "Retrieve failed!")<br>end if |

By default, 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.