Invoking component methods
Once a connection to a Jaguar server has been established
and a proxy object created, the client application can begin using
the server components.
How to invoke a method
To invoke a component method, 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.
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, Jaguar uses the default package
specified in the Application property of the Connection object:
1 |
// Global variable: |
1 |
// connection myconnect |
1 |
1 |
uo_customer iuo_customer |
1 |
string ls_custid |
1 |
long ll_rc |
1 |
1 |
ls_custid = Trim(sle_custid.text) |
1 |
ll_rc = myconnect.CreateInstance(iuo_customer) |
1 |
if ll_rc <> 0 then |
1 |
MessageBox("CreateInstance failed", ll_rc) |
1 |
end if |
1 |
if iuo_customer.retrieve_balance(ls_custid) != 1 then |
1 |
MessageBox("Error", "Retrieve failed!") |
1 |
end if |
Example 2 This script instantiates a component on the server and assigns
the object reference to a variable whose data type 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
Jaguar package name:
1 |
// Global variable: |
1 |
// connection myconnect |
1 |
1 |
uo_person lnv_object |
1 |
string ls_custid |
1 |
long ll_rc |
1 |
1 |
ls_custid = Trim(sle_custid.text) |
1 |
ll_rc = myconnect.CreateInstance(lnv_object, & |
1 |
"PB_pkg_1/uo_customer") |
1 |
if ll_rc <> 0 then |
1 |
MessageBox("CreateInstance failed", ll_rc) |
1 |
end if |
1 |
if iuo_customer.retrieve_balance(ls_custid) != 1 then |
1 |
MessageBox("Error", "Retrieve failed!") |
1 |
end if |
Destroying the proxy object instance
After you’ve finished using a Jaguar component, you
can explicitly destroy the Jaguar proxy object by using the DESTROY
statement, or you can let PowerBuilder’s garbage collection
facility clear the object out of memory for you automatically. In
either case, the destruction of the client-side proxy object has
no effect on the lifecycle of the server component. Destruction
of the server component is handled by Jaguar.
If the Automatic Demarcation/Deactivation setting
is disabled for a component, and you close the client application
while the component is still bound to the client (the component
did not call SetComplete or SetAbort), the component will not
be
deactivated. To ensure that the component instance is deactivated,
you can do one of the following things:
- In
the Close event of the client application, invoke a method of the
server component that deactivates the component (by calling SetComplete
or SetAbort). - Set the Timeout property for the component to a
value other than 0. If the component’s Timeout property
is set to 0, the component will never time out.