Foxhound is the better* Database Monitor for SQL Anywhere.
*better: More thorough, more relevant, more effective.
...more Alerts, more All Clears, more details, more control in your hands.


Breck Carter
Last modified: July 11, 1996
mail to: bcarter@bcarter.com



Tracking The Elusive DWObject

What is this new DWObject type and how do I use it?

A well-kept secret, that's what it is, a chameleon in more ways than. First of all, it is fairly well documented but that documentation is very hard to find. Second, its properties vary wildly depending on how it is used.

And as for the question "How do I use it?" the answer is "Very carefully!" Carefully, that is, if you don't want to cause a fatal memory leak.

Here's what the PowerBuilder 5 Object Browser has to say about DWObject; in other words, not much:

To find the truth about DWObject you must open up the Help and:

  1. Start at the Contents page, then
  2. Pick "DataWindow objects",
  3. Pick "Data expressions",
  4. Click on "Syntax for one or all items", and finally
  5. Scroll down to the "Usage" section.

Now, to fully understand the new dot notation syntax for DataWindows you should really have a look at the other topics visible at Steps 3 and 4, but we're on a hunt here. What you see at Step 5 is a rhetorical question "Is the expression a DWObject or data?" It turns out that:

   dw_1.object.empname

is a "DWObject" and (trust me on this) you can declare and assign it to a variable:

   DWObject ldwo_empname

   ldwo_empname = dw_1.object.empname

(At this point you're probably wondering why the Help has to be so hard to find and so am I. Go ahead, try using Help - Search to look for "DWObject" if you want. Or use the full text search "Find+" button. The 5-step process given above is still the best way to find a description of DWObject.)

Here's an example of what you can do with the DWObject; this code dynamically changes the height of the column called pkey and then displays "yes" or "no" depending on whether that column is updatable:

   DWObject ldwo_column

   ldwo_column = dw_concurrency.object.pkey

   ldwo_column.height = 45

   MessageBox ( "PKey Updatable?", &
      string ( ldwo_column.update ) )

As mentioned earlier the properties of DWObject vary wildly. They match the properties of the DataWindow component that has been assigned to the DWObject variable. Here's how to find out what they are:

  1. Open the PB5 Help and start at the Contents page, then
  2. Pick "DataWindow objects",
  3. Pick "Property expressions" for the basic rules, OR
  4. Pick "DataWindow object properties" for the details, then
  5. Pick "Column", "Computed field", etc. depending on your needs.

At many stages in your journey through Help a "See Also" button will be visible... it's quite valuable for finding answers to the 1,001 questions that are sure to come to mind. And you'll soon find that the power of DWObject extends far beyond it's use as an alternative to calling describe() and modify(). For example, you can use a DWObject variable to fill an array with all the values in a column for a specified range of rows.

The danger of memory leaks may or may not be real. There have been rumors of such a problem but I've been unable to duplicate the problem. What is clear, however, is that DWObject variables can be quite fat in terms of memory usage, and the memory is allocated when the variable is assigned as in:

   ldwo_column = dw_concurrency.object.pkey

In other words, the assignment is doing an implied create. The good news is that (subject to the rumors) it looks like PowerBuilder takes care of freeing up the memory when the variable falls out of scope.

To do your own experiments, declare the following external function:

   function ulong GetFreeSpace &
      ( UnsignedInteger aui_dummy ) library "kernel.exe"

and then from time to time display the bytes of free memory:

   st_memory.text = string ( GetFreeSpace ( 0 ) )

One thing you may notice is the space required for a DWObject variable depends on whether the DataWindow buffer is empty or not. Since you can use DWObject to fill an array with column values, the different memory usage may imply that a "deep copy" of column values has taken place. Further experimentation is certainly warranted here, an exercise for the reader: If true, is it a bug or a feature?


Breck Carter can be reached by phone at (416) 763-5200 or via email at bcarter@bcarter.com.