|
Home Up Database Steps Objects & Tools PB Window Steps Event Scripts
| |
 | There are no steps on this page, just
discussion of concepts, tools, & steps to be taken on the next
page.
|
 | Before getting into the Window Painters, your
Workspace should show a properly named Application Object, and your
folder should have appropriately named pbw, pbt, pbl, & db
files. Your database should have at least two tables,
Ledger Accounts and Goods & Services. And, the new DDDW
& DDDL edit styles should be in installed in the Extended
Attributes and put into columns with foreign keys.
If you discover that something isn't right in the
database while building these Windows, the best thing to do is go back
and correct the database by dropping and adding, then delete any
objects built with reference to the incorrect database and rebuild
them.
|
 | The Application Object |
The application object is not a visual object
anywhere but in the IDE,
but it is an important one.
The script for its Open event
sets up the database with reference to the pb.ini file and
launches the main button panel, shown next.
There is also a function defined, parseline,
which is not a visual object. It pulls the fields out of
asterisk delimited strings so that they may be used in
programs.
The first use of parseline is to parse the
Enterprise Number & Name from the enterprise control record,
which supplies the title for the main panel. Since other
uses of parseline will be found in other of your application's
windows, it's a good idea to place this function as an Object in
in the Application Object so that it will be readily available for
other scripts.
The scripts for all these objects follow on the
next pages.
 | The Main Panel:
|
w_main_panel is a Window, each button is a Control Button, or could be a picture button,
replaced/augmented with a menu choice, or other object the user uses to
launch the
desired function. We're only concerned with the first four
buttons for this exercise.
A script at the open event of w_main_panel opens
and reads the 'enterprise definition record', enterprise.def and uses it to supply
the title for the panel. The script depends on the Function
parseline, which is mentioned just above.
Each command button needs a script for its
GetFocus event with a single line, this.default = true. This
lets the user move around the button panel with the tab key and
press [Enter] to launch the button's function.
Some of the buttons of the GUI need a
'keyboard shortcut' . These are indicated on the control
with an underlined letter in the control's caption. The [Alt] shift key + the
underlined letter is a 'keyboard shortcut' that can be used instead of
clicking the button with the mouse. The shortcut keys are
nominated by placing an ampersand (&) in front of the Text
property for the control.
Make your Main Panel distinctive for your
Enterpirse. And, plan to group the buttons or other controls
in an orderly fashion. There's no reason that buttons should
be the only type of control on the Main Panel, by the way, and
some of the best projects I've seen have included Menus, DropDown
Lists for selection of often-used records & reports, and have
otherwise made better use of the limited real-estate on the main
panel.
 | Table maintenance Windows:
|
After building a Main Panel that works you'll be
setting up to make a class of 'table maintenance windows'.
The prototype is built using this schematic:

It uses a 'master/detail' sort of
presentation where the user scrolls through entries in the
'master', or 'lookup' window at upper left and highlighted records
are displayed in the 'detail', or 'maintenance' window below it.
dwc_lookup and dwc_maint are DataWindow Controls that
are named generically so that they make sense when the window is
inherited to make other windows. The DataSource Property of each
DataWindow Control contains the name of a DataWindow that is
linked to the particular table being maintained.
All the first tables use a key
named id, so the event script for a Click on w_lookup can handle
any of these tables.
Some DataWindows
contain fields that are foreign keys to other tables, and these
also have DataWindows built to populate their DropDownDataWindows.
Any of these are represented in the above schematic as 'dw_other_lookup',
and would be like dw_ledacc_lookup or dw_entity_lookup which would
populate DDDW edit-styles in the Ledger Account & Primary
Supplier Id columns of a Goods & Services record.
Since all the windows in the 'table maintenance'
series have the same functions, they can all be inherited from the
first one built. In this case w_ledacc_maint was built and its
scripts debugged, then the other four related windows (including
Accounting Date Maintenance) inherited it and had slight changes
made to accommodate their tables. Here is w_ledacc_maint:

After w_ledacc_maint was debugged, the other
windows were inherited from it and changes made to their title, to
the Data Object properties of dwc_lookup, and to the dimensions
and Data Object properties of dwc_maint to suit the table being
maintained.
Notice that these windows may have Drop Down
Data Windows that allow the user to select foreign keys from a
drop-down list. Here is w_gs_maint, with all its scripts and
most of its properties inherited from w_ledacc_maint:

Here is the window with the drop down lists
filled in:

 | Tab stops in both Windows & DataWindows:
Make sure that the tabs are set properly in
each window you construct. The tabs are set according to
the order in which controls are added to the window & this
may not make a sensible route for the user who is navigating
the Window with the Tab Key & Enter Key. Click the
Tab Order button while in the Window Painter so you can
highlight & change the tab order on each of the Window's
controls. Click the Tab Order button to get out of the
Tab Editing mode:

Data Windows may also need their Tab
Order edited. While in the DataWindow Painter you can click on
the Tab Order button so that the Tab Order for each Column object may
be set appropriately:

|
 | Update Properties of Column
Objects in Data Windows are important for how the application
behaves. Lookup Windows, where the user will never be changing
the data, should have the update properties of the columns objects set
to allow no update. This avoids an ugly incident where
the user appears to be able to edit data in the Lookup Window, or
where a DDDW edit style deploys inappropriately. |
 | GUI Properties on these table
maintenance windows are mostly
left at default at design time. The event scripts set
the enabled/disabled properties of the controls as appropriate
for the state of the GUI so most properties may be left at their
defaults to get your prototypes working quickly. But
there are a few touches that make the prototype act better. Change
the title property of w_ledacc_maint and each of the
windows that is inherited from it. Plan
to customize the look of your GUI, add graphics, or perhaps
the rules of the interface (as long as your windows support
keyboard data entry) as you polish your prototype. |
 | Scripts are the glue that makes PB Objects work
together. Here are elements used in the prototype's scripts:
Database Connect statements are important in the Open Event of
the Application Object. We'll put them where they belong later along with a
line of script opening the application's first Window. These serve to point your application to the right database. Make sure to
place a copy of (not the only thing) PB.INI in the directory with the PB Library so that
you can point each version of your project to the desired database easily.
Find the 'connection string' in the Database painter by right-clicking
on the Installed ODBC interface & choosing the Preview tab.
You'll be copying & pasting this into your Application Object's Open Event
Script. Here's mine, if my SS# was 123-1234-9191
// Profile gs9191
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm = "Connectstring='DSN=gs9191'"
open(w_main_panel)
Imbedded SQL is important in PB Scripts:
If the script will be updating a database make sure that all these
statements are executed and that no Window that has done a CONNECT is
closed without doing a DISCONNECT.
CONNECT USING SQLCA;
COMMIT USING SQLCA;
ROLLBACK USING SQLCA;
DISCONNECT USING SQLCA;
These are the SQL control statements in scripts that connect to and
control updates to the database. If you leave one out there will be debugging to
follow.
|
By convention of this class: cb references a Command Button, dw a
DataWindow, dwc a DataWindow Control, st is StaticText. Objects are named with a
lower case prefix indicating the class of object, and with a Capital letter at the start
of each word past the prefix.
 | Here are PowerScript keywords used in the short
scripts of the prototype so far. The MessageBox function is
especially important for debugging: |
MessageBox('Label', '1st part of message ' + string (some.number)
+ '<--> '+ some.string, 'Exclamation!') is a valuable tool for debugging. It
can also retrieve values from the user, edit them, and not proceed until a response has
been made to the message, as used in the clicked event for cb_delete in our example.
cb_someName.Enabled = true readies a control button to generate
a Clicked! event for the users, or = False 'greys out' the control and makes it ignore their
clicks.
cb_update.TriggerEvent(Clicked!) calls the script for the
Clicked! event of the ControlButton cb_update. This is so that a
control's events can be initiated from the script of another
control.
dwc.SetTransObject(SQLCA) & dwc_lookup.Retrieve() at open of
table maintenance Window. Each DataWindow Control needs its
TransObject set to the SQLCA set up in the Application's Open
event script. The Lookup DataWindow Control's Retrieve
method us used to populate the DataWindow with reference to the
database.
dwc.Enabled works the same as it does for
a command button, as above.
dwc_SomeName.SetFocus() moves to GUI's focus to the named dwc &
triggers any GetFocus events that may be scripted.
dwc_SomeName.GetItemNumber(row,"recordKey") (or Get
ItemString) to return the key from a multi-row DataWindowControl used to select records.
This is important to 'synchronize' the Detail/Maint DataWindow
with the Master/Lookup DataWindow above it, and is found in the
RowFocusChanged event script for the Lookup windows.
dwc_SomeName.DeleteRow(0) deletes the row currently in the control.
dwc_SomeName.InsertRow(0) inserts a new row and clears the control to
accept our text entries.
dwc_SomeName.Reset clears the control.
dwc_SomeName.Update() returns a 1 if the text in the control passes edits
and should be commited, or an error message otherwise.
st.Text = "A prompt for the user"
is used to keep the prompt on the screen refreshed and appropriate
for the user. Intrepid students might like to investigate
PowerBuilders's microhelp for this functionality. It's easy to
simulate this by putting a short, wide Static Text control along
the bottom edge of a window.
Open(object) allows a script to call another object and trigger
its Open event's script
Close(object), often Close(parent) shuts down the object,
whether it be a Window or other function or process. Parent is a
generic form that refers to the parent object of the object with
the script: a Command Button's parent would be the Window on which
it is placed.
 | Next are steps for
building up the prototype's table maintenance windows. If your
database is working fine & has all it's edit styles and validation
rules it's time to start working with your application... |
[ Up ] [ Database Steps ] [ Objects & Tools ] [ PB Window Steps ] [ Event Scripts ]
|
|