SharedObjectGet PowerScript function
Description
Gets a reference to a shared object instance.
Syntax
1 |
<span>SharedObjectGet</span> ( <span>instancename </span>, <span>objectinstance</span> ) |
Argument |
Description |
---|---|
instancename |
The name of a shared object instance |
objectinstance |
An object variable of type PowerObject |
Return Values
ErrorReturn. Returns one of the following values:
-
Success! – The function
succeeded -
SharedObjectCreateInstanceError! – The
local reference to the shared object could not be created -
SharedObjectNotExistsError! – The instance
name has not been registered
Usage
SharedObjectGet retrieves a reference to
an object that was created with SharedObjectRegister.
You can use a shared object on a PowerBuilder client to simulate
an asynchronous call to EAServer.
The main thread on the client makes an asynchronous call to a function
on the shared object, passing it a callback object that is notified
when processing has finished on the server. The method on the shared
object makes a synchronous call to the EAServer component method
that performs processing. Since the shared object is running in
a separate thread on the client, the main thread on the client can
proceed with other work while the process runs on the server.
Examples
This example shows how you might use a shared object
to make an asynchronous request against an EAServer component
method and return data back to a client application window. The
client has a Retrieve button on a window, a SetDW function,
a shared object, and a callback handler. The component deployed
to EAServer retrieves employee
information from a database.
The Retrieve button on the window creates a shared object
that communicates with EAServer as
well as an instance of a callback handler:
1 |
// instance variables<br>// uo_sharedobject iuo_sharedobject<br>// uo_callback iuo_callback<br>long ll_rv<br> <br><span>SharedObjectRegister</span>("uo_sharedobject","myshare")<br><span>SharedObjectGet</span>("myshare",iuo_sharedobject)<br> <br>iuo_callback = CREATE uo_callback<br>// Pass a reference to the window to<br>// the callback object<br>iuo_callback.passobject (parent)<br> <br>iuo_sharedobject.post retrievedata(iuo_callback) |
The SetDW function applies the contents
of the DataWindow blob returned from the EAServer component
to a DataWindow control in the window:
1 |
long ll_rv<br> <br>ll_rv = dw_employee.<span>SetFullState</span>(ablb_data)<br>if ll_rv = -1 then<br> MessageBox("Error", "SetFullState call failed!")<br>end if<br> <br>return ll_rv |
The Constructor event of the shared object uses a custom Connection
object called n_jagclnt_connect to
connect to the server. Then it creates an instance of the EAServer component:
1 |
// Instance variables<br>// uo_employee iuo_employee<br>// n_jagclnt_connect myconnect<br>Constructor event |
1 |
long ll_rc<br>myconnect = create n_jagclnt_connect<br>ll_rc = myconnect.ConnectToServer()<br>ll_rv = myconnect.CreateInstance(iuo_employee, &<br> "uo_employee") |
The shared object has a single function called RetrieveData that
makes a synchronous call to the RetrieveData function
on the EAServer component.
When the function completes processing, it calls the Notify function asynchronously
on the callback object, posting it to the DataWindow blob returned
from the server component:
1 |
blob lblb_data<br>long ll_rv<br>ll_rv = iuo_employee.retrievedata(lblb_data)<br>auo_callback.post notify(lblb_data)<br>return ll_rv |
When the EAServer component
has finished processing, the shared object notifies a user object
called uo_callback, which in turns
notifies the w_employee window. The uo_callback object
has two functions, Notify and PassObject.The Notify function
calls a function called SetDW on the w_employee window, passing
it the DataWindow blob returned from the server component:
1 |
long ll_rv<br>ll_rv = iw_employee.setdw(ablb_data)<br>if ll_rv = -1 then<br> MessageBox("Error", "SetDW call failed!")<br>end if<br>return ll_rv |
The callback handler’s PassObject function
caches a reference to the w_employee window
in the iw_employee instance variable.
The function takes the argument aw_employee,
which is of type w_employee, and returns
a long value:
1 |
iw_employee = aw_employee<br>return 1 |
The EAServer component
is a PowerBuilder user object called uo_employee. The uo_employee object
has a function called RetrieveData that uses
a DataStore to retrieve employee rows from the database:
1 |
// instance variables<br>// protected TransactionServer txnsrv<br>// protected DataStore ids_datastore<br>long ll_rv<br>ll_rv = ids_datastore.Retrieve()<br>ll_rv = ids_datastore.<span>GetFullState</span>(ablb_data)<br>txnsrv.SetComplete()<br>return ll_rv |
See Also
-
SharedObjectRegister, SharedObjectUnregister, GetFullState and SetFullState methods
for DataWindows in the DataWindow Reference or the online Help