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:

  1. In the User Object painter, define and save a standard class user object inherited from the built-in DataStore object.

  2. 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 section called “About the User Object painter” in Users Guide.

To define the standard class user object:

  1. Select Standard Class User Object on the PBObjects tab in the New dialog box.

  2. 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.

  3. Specify the name of the DataWindow object in the DataObject box in the Properties view and click OK.

  4. Customize the DataStore by scripting the events for the object, or by defining methods, user events, and instance variables.

  5. Save the object.

To use the user object in your application:

  1. Select the object or control for which you want to write a script.

  2. Open the Script editor and select the event for which you want to write the script.

  3. 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:

    uo_cust_dstore lds_cust_dstore
     lds_cust_dstore = CREATE uo_cust_dstore
     lds_cust_dstore.SetTransObject (SQLCA)
     lds_cust_dstore.Retrieve()
     /* 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.

  4. Compile the script and save your changes.