DataWindow spy
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
![Image](http://code.intfast.ca/images/spy.jpg)
It is a utility which gives PowerBuilder programmers a magic ability to quickly and easily see hidden DataWindow information in run-time without using the debugger. The utility increases productivity of developers and production support analysts, adding them speed and comfort: in order to instantly see hidden information, they simply click on appropriate DataWindow's areas while Shift is pressed. And that - instead of boring and time-consuming debugging and exploring the application in the development environment!
The spy shows not only all the hierarchy of the visual objects (from the window and the menu to the DataObject) but also their PBLs - this feature is especially useful for the project's newcomers: now they are exempted from never-ending scrolling in PB's Objects Browser. The displayed info can be copied to the Windows clipboard; for example, you can copy the DW's SQL SELECT, then paste it into a database tool (like TOAD or PB's database painter) and run looking for a retrieval bug.
This utility works only when the application is running from PB, NOT as a standalone executable (we don't want to confuse the users!).
The Spy doesn't require PFC or any other kind of framework: it is easily added to any PB (version 7 or later) project - by inserting a few lines of code!
It's not a commercial product - in fact, I created it for myself many years ago, and it travels with me from project to project, but if somebody wants to use that small helper to facilitate his/her developer's work - please help yourself, it's not copyrighted.
HOW TO ADD THE SPY TO AN APPLICATION?
1. Save the file
2. Add it to your application's library list.
3. Add the following code fragment to Clicked event of your ancestor DW (like u_dw in PFC) (you can change Shift to another key or keys combinations if you wish, or if Shift is already in use in your application):
- Code: Select all
//------------------------ Open DW Spy ------------------------ BEGIN
n_parm lnv_parm
if KeyDown(KeyShift!) then
if Handle(GetApplication()) = 0 /* running from PB, NOT as a standalone executable */ then
if IsNull(row) or IsNull(dwo) then
MessageBox("DW Spy", "To open DW Spy, click the datawindow itself (not an object, placed on top of it).")
else
lnv_parm.uf_set(w_spy.PARM_NAME__DW, this)
lnv_parm.uf_set(w_spy.PARM_NAME__ROW, row)
lnv_parm.uf_set(w_spy.PARM_NAME__COL, dwo.name)
OpenWithParm(w_spy, lnv_parm) // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> http://code.intfast.ca/viewtopic.php?t=3
end if
end if
end if
//------------------------ Open DW Spy ------------------------ END
4. Save. That's it!
HOW TO USE THE SPY?
![Image](http://code.intfast.ca/images/hat.jpg)
To call the Spy, simply press Shift and click a DataWindow in a running application. If you want to get information about a row or a field then click just on that row/field. That's how the Spy is looking just after calling:
![Image](http://code.intfast.ca/images/w_spy.jpg)
The next paragraphs describe the functionality of the window's buttons.
On-Window Hierarchy
Vertically - hierarchy of displayed objects (from window to DW's DataObject or stored proc).
Horizontally - inheritance chain of each inherited object (including PBLs).
An example of information, displayed for a DW, placed on a tab and having a stored proc as the data source:
- Code: Select all
###### WINDOW: ###################################
w_policy (C:\proj\policy.pbl)
w_modal (C:\proj\lib.pbl)
w_response (C:\proj\lib.pbl)
w_base (C:\proj\lib.pbl)
###### TAB: ######################################
tab_policy
###### USEROBJECT: ###############################
tabpage_driver
u_tab_driver (C:\proj\driver.pbl)
u_tab (C:\proj\lib.pbl)
u_custom_visual (C:\proj\lib.pbl)
###### DATAWINDOW: ###############################
dw_driver_claims
u_dw_list_updatable (C:\proj\lib.pbl)
u_dw_list (C:\proj\lib.pbl)
u_dw (C:\proj\lib.pbl)
###### DATAOBJECT: ###############################
d_driver_claims (C:\proj\driver.pbl)
###### STORED PROCEDURE (DW'S DATA SOURCE): ######
s_driver_claims
Window's Menu
The menu attached to the window and its inheritance chain (including PBLs).
Size & Coordinates
Size & Coordinates of the window. Useful to troubleshoot a window whose size and coordinates are set dynamically in a script.
Data Source
DW's Data Source (SQL Select or Stored Procedure). If retrieval arguments exist in the DW then there are the following changes:
1. The button's text becomes "Data Source and Arguments".
2. The displayed message contains the arguments' names, datatypes and the values the last retrieval has been performed by.
Invisible Fields
For each invisible field, the following information is shown:
* Name in the DataWindow.
* Name in the DB (if different from the name in the DataWindow).
* Value (if it has been changed then the both - the Original and the Current).
* Data type.
* For computed fields: the expression and the value evaluated for the clicked row.
* Updatable or Not Updatable.
* DWItemStatus of the field.
If the DW has no rows then only row-independent info is shown.
Sort Expression
Displays the expression the DW is sorted by if a sort is defined. Otherwise the button is disabled and titled "No Sort Applied".
Filter Expression
Displays the expression the DW is filtered by if a filter is defined. Otherwise the button is disabled and titled "No Filter Applied".
Filtered Rows
Displays the data, contained in the Filter! buffer, using the original DataObject of the investigated DW. If the Filter! buffer is empty, then the button is disabled and titled "No Filtered Rows".
The DW can be sorted by one column. To sort in ascending order, double-click on the field (the column's font becomes blue). To change sorting to descending, make one more double-click on the same column (the font becomes red). To restore the original sorting, close and re-open the Spy.
Deleted Rows
Displays the contents of the Delete! buffer using the original DataObject of the investigated DW. If the Delete! buffer is empty then the button is disabled and titled "No Deleted Rows".
Size & Coordinates
Size & Coordinates of the DW. Useful to troubleshoot a DW whose size and coordinates are set dynamically in a script.
Row Status
DWItemStatus of the clicked row.
Updated Fields
Fields (visible and invisible) of the clicked row which have been updated (by the user or programmatically) but not saved yet, with their old and new values.
Field Info
Regular field: name in the DataWindow (and DB name if differs), data type, Updatable/Not Updatable, DWItemStatus, value (useful when the field width is not enough to display the whole text), the expressions for Enabled and Update properties (if exists), the list of the field's attributes and their current values. If the field's value has been changed then both the Original and the Current Values are shown.
Computed field: expression and data type.
Field with DropDownListBox: Code Table (pairs 'Display Value' - 'Data Value')
Field with DropDownDataWindow: values of Display Column - Data Column, DWC's DataObject and Data Source, retrieval arguments etc.
DDDW's Data
Displays the data, contained in the DropDownDataWindow of the clicked field (using the original DataObject of the investigated DDDW).
The Spy displays the contents of the DataWindowChild's Primary! buffer only. If the DDDW contains filtered or deleted rows then a message box pops up suggesting to open an additional instance of the DW Spy (by clicking the DW on the first instance) and then to click on "Filtered Rows" / "Deleted Rows" button on that additional instance. A similar message is also shown if there are invisible fields in the DDDW (in this case the suggestion is to click the "Invisible Fields" button on the additional Spy's instance).
![Image](http://code.intfast.ca/images/top_secret.jpg)