



Download Source
Thank you Sandy Barletta!
Just after the earth began to cool (I think it was in the PB3 time frame), I discovered the DWSyntax tool created by Sandy.
‘Round about that time I had been exporting DataWindow objects (this was before “edit source” folks) in order to get functional syntax for my dwModify() calls. Lo’ and behold I discovered this nifty GUI that would allow me to browse the dwDescribe(), dwModify(), SyntaxFromSQL() argument syntax for any DataWindow item or for the DataWindow object itself.
Fast forward to the present day. Let’s say you need to change the expression of a computed field at runtime, much as I illustrated in another tip on dynamically “creating” DataWindow groups.
From the PowerBuilder IDE, open the “New” dialogue. Select the “Tool” tabpage, and then select the “DataWindow Syntax” item.

From the tool’s menu, navigate to Syntax>Modify>Attributes.

From the “Object” DDLB, choose “ComputedField”.

From the “Attributes” listbox, select “Expression”.

You’re then presented with two versions of the syntax’s template; one for Modify() call usage, the other if you prefer dot notation. Copy/paste the template syntax and replace the bracketed portions as appropriate with explicit values or with reference variables.
DWSyntax offers this functionality without breaking a sweat. To really start utilizing the power of the tool, browse its “create” syntax capabilities…

…or its GUI have you build SyntaxFromSQL() syntax from scratch…

If you’re relatively new to PowerBuilder, you may find this tool to be instructive. If you’re an experienced PowerBuilder developer, I hope you enjoy the productivity this tool will provide.




Greenbrier builds and leases railcars. When the company decided to develop customer interfaces for the Web it chose Sybase EAServer as their Web application server. EAServer gave Greenbrier the features it needed and seamless integration with PowerBuilder code made it the perfect tool to take its large library of PowerBuilder applications online.




Here’s a DataWindow tip…and a half.
Unless you want to dynamically build a DataWindow object from scratch at runtime (it’s do-able…but quite involved), there’s no direct way to create a group for a DataWindow object in an ad hoc manner. Here’s a workaround.
First, insert a computed field in an extant DataWindow object and give it an expression that’s an empty string. For the sake of this tip the computed field’s name will be “dynamicgroup”.

Then create a group based on this computed field.


Format the DataWindow object according to your needs and save.
Now at runtime, modify the computed field’s expression to have the value of the column name by which you wish to group the result set.
dw_employees.setredraw( FALSE )
dw_employees.Modify(”dynamicgroup.Expression=’” + as_coltogroup + “‘” )
dw_employees.setsort( as_coltogroup + ” A”)
dw_employees.sort( )
dw_employees.groupcalc( )
dw_employees.setredraw( TRUE )
After calling SetSort() and Sort() to sort by the column on which you’re grouping, don’t forget to call GroupCalc() to recalculate the breaks in the groupings.
Certainly this technique may be adapted to implement more than one grouping level. For those of you who maintain and enhance frameworks, the sample code fragment can certainly be made more generic as far as the reference to the DataWindow control and to the name of the computed field(s).
OK, here’s the half (.5) tip.
You’ve defaulted the value of the computed field’s expression to an empty string. This will work fine for grouping on columns of type string. However, for columns of other data types, you’ll need to invoke the DataWindow expression function String() to convert the non-string columns’ values to strings in order for the runtime modification to have the desired effect. Here’s how the accommodation appears in the sample code from earlier in this tip…
dw_employees.Modify(”dynamicgroup.Expression=’String(” + as_coltogroup + “)’” )




Perhaps you’ve enabled the titlebar and control menu of a DataWindow control. You may even want the users to be able to minimize/maximize and reposition the control at runtime.

Now you’d like to trap when the user interacts with the control in this fashion in order to execute some logic when they do. Perhaps you’d like to know when/if the user closes the DataWindow control.

Go ahead and map a custom event for the DataWindow control to the pbm_syscommand Event ID.

For purposes of demonstration, I’ve placed a singlelineedit control on a window and assigned the commandtype argument value of the event (an unsignedlong) as a string to the text property of the sle.
sle_commandtype.text = String ( commandtype )
In the screenshot, you can see that I’ve trapped the user clicking on the titlebar of the DataWindow control with a commandtype value of 61458.

For your reference, I’ve included a roster of commandtype values here in this tip. Happy trapping!
61458: TitleBar Clicked
61456: “Move” invoked from Control Menu (cursor keys can move DW control)
61587: Control menu dropped down
61536: DataWindow Control Closed by Control Menu (or “X”)
61472: DataWindow Control is Minimized
61488: DataWindow Control is Maximized or resized by border interaction
61728: DataWindow Control size is “Restored”
61441: DataWindow Control is resized by left border interaction
61442: DataWindow Control is resized by right border interaction
61443: DataWindow Control is resized by top border interaction
61444: DataWindow Control is resized by NW corner interaction
61445: DataWindow Control is resized by NE corner interaction
61446: DataWindow Control is resized by bottom border interaction
61447: DataWindow Control is resized by SW corner interaction
61448: DataWindow Control is resized by SE corner interaction


More Options ...
Categories
Tag Cloud
Blog RSS
Comments RSS

Void « Default
Life
Earth
Wind
Water
Fire
Light 