Using a custom DataStore object
This section describes how to extend a DataStore in PowerBuilder
by creating a user object.
You might want to use a custom version of the DataStore object
that performs specialized processing. To define a custom DataStore,
you use the User Object painter. There you specify the DataWindow
object for the DataStore, and you can optionally write scripts for
events or define your own methods, user events, and instance variables.
Using a custom DataStore involves two procedures:
- In the User Object
painter, define and save a standard class user object inherited
from the built-in DataStore object. - Use the custom DataStore in your PowerBuilder application.
Once you have defined a custom DataStore in the User Object
painter, you can write code that uses the user object to perform
the processing you want.
For instructions on using the User Object
painter in PowerBuilder, see the PowerBuilder User’s
Guide
.
To define the standard class user object:
-
Select Standard Class User Object on the
PBObjects tab in the New dialog box. -
Select datastore as the built-in system type that
you want your user object to inherit from, and click OK.The User Object painter workspace displays so that you can
define the custom object. -
Specify the name of the DataWindow object in the
DataObject box in the Properties view and click OK. -
Customize the DataStore by scripting the events
for the object, or by defining methods, user events, and instance
variables. -
Save the object.
To use the user object in your application:
-
Select the object or control for which
you want to write a script. -
Open the Script view and select the event for
which you want to write the script. -
Write code that uses the user object to do the
necessary processing.Here is a simple code example that shows how to use a custom
DataStore to retrieve data from the database. First it instantiates
the custom DataStore object, then it sets the transaction object
and retrieves data into the DataStore:1uo_cust_dstore lds_cust_dstore1lds_cust_dstore = CREATE uo_cust_dstore1lds_cust_dstore.SetTransObject (SQLCA)1lds_cust_dstore.Retrieve()1/* Perform some processing on the data... */Notice that this script does not assign the DataWindow object
to the DataStore. This is because the DataWindow object is specified
in the user object definition.Changing the DataWindow object at execution time When you associate a DataWindow object with a DataStore in
the User Object painter, you are setting the initial value of the
DataStore’s DataObject property. During execution, you
can change the DataWindow object for the DataStore by changing the
value of the DataObject property. -
Compile the script and save your changes.