Introduction to PowerBuilder

HomePrevious Lesson: Querying the Database Dynamically
Next Lesson: Populating User Defaults in the Login Window

Sharing Data between DataWindows

Before we proceed into the technical stuff, we have a question to answer. Why do we need two DataWindows? That is because, we would like to give the user a form like interface for query criteria entry and report format for report display.

Though the presentation styles are different in these two DataWindows, the data source and the data are same. In that case, we can ask PowerBuilder to share the data between these two DataWindows. This can be done by calling the ShareData() function.

Append the following line of code to the Open event for w_product_master window.
// Object: w_product_master window
// Event: Open
// Append the following code to the existing code.
dw_query.ShareData( dw_product)

With this code, dw_product is sharing data from dw_query. dw_query is called the "Primary DataWindow" and dw_product as "Secondary DataWindow". A primary DataWindow can share data with any number of DataWindows. A secondary DataWindow also can share data with another DataWindow in which the secondary DataWindow becomes the primary DataWindow.

Only the data is shared between the DataWindows, not the presentation styles. That means, DataWindows can have different sort criteria and presentation styles. If you delete a row in one DataWindow, the data source is same, it is also deleted from all other sharing DataWindows. Similarly, if you add a row, it will be available in all shared DataWindows.

Sharing data allows us to utilize the resources more efficiently. At this point run the application and see how the 'Query' and 'Retrieve' options are working.

We wrote code for all options in the window, except for closing the window. Write the following code for it.
// Object: cb_close in w_product_master window
// Event: Clicked
Close(Parent)

The above code closes the window. Once the window is closed, the control goes back to the application's open event (which opened this window). There is no code after opening this window. Hence, PowerBuilder closes the application.
HomePrevious Lesson: Querying the Database Dynamically
Next Lesson: Populating User Defaults in the Login Window