Friday, April 27, 2012

Using DataStores instead of hidden DataWindows

Pre-5.0 developers had to use hidden DataWindows to get and process data behind the scenes.  Version 5.0 offered the DataStore, which has alleviated the need for hidden DataWindows.  Here are several reasons to use DataStores instead of hidden DataWindows:

1) Hidden DataWindows, although invisible, still have a visual component that takes up memory.
2) DataStores can be destroyed after they have served their purpose, releasing the memory they use.
3) DataStores are the “bridge” to 3-tier architecture, so you’ll make your life easier when you move your application from traditional Client/Server to 3-tier or Web based.
4) Since DataStores are usually defined as instance variables, you can make them private, unlike window controls.
Do not forget to Destroy them before closing the window / user object they are used in, or the you’ll get memory leaks.  Here’s the code need to use a DataStore:

[in instance variables]
DataStore ids_Source

[in Open / Constructor event]

ids_Source = Create DataStore // Create an instance of the datastore
ids_Source.DataObject = “d_DataWindow_Name”
ids_Source.SetTransObject(SQLCA)

[in Close / Destructor event]
IF (IsValid(ids_Source)) Destroy ids_Source // Release the memory

No comments:

Post a Comment