Step 5: Adding Buttons and Triggers

In this section:

So far you have created a Winform that displays data, that is, the Car and Country fields and the grid displaying BodyStack columns. However, you have not created a way to traverse the data or to update the data source. You cannot process the data.

In this step you add triggers and command buttons to provide a way to process the data. A trigger is a procedure that is invoked—"triggered"—by a specified event. The procedure can be a function or a system action. (Triggers are also known as event handlers, and functions are referred to as cases in the Winform Painter.) The event can be something the user does in a Winform, such as clicking a button. For example, a user clicking a Cancel button triggers a system action that closes the Winform.

In this section, you add buttons and triggers to the Winform and assign the triggers to the buttons. By clicking one of these buttons, the user triggers a function that pages through the data and updates the data source, or invokes a system action that closes the Winform or exits the application.


Top of page

x
Adding the First Button and Trigger

The first step is to add a command button to the Winform. This button triggers a function that moves backward through the data, displaying values for the previous car brands.

Try it now:

  1. Select the Button option from the Objects menu.
  2. In response to the prompt at the bottom of the screen to define the top left corner of the button, position the cursor at row 20, column 5 (using the terminal emulator's coordinates) and press Enter.
  3. In response to the next prompt, to define the button's bottom right corner, position the cursor at row 20, column 20, and press Enter.

The Button dialog box opens.


Top of page

x
Text

You can type descriptive text to be displayed on the face of the button in the Text entry field. This text usually describes what the button does and includes the name of the button's shortcut key.

Try it now: Type the following text and include two spaces between the description and key name for reading ease: Previous Car F1.


Top of page

x
Justification

The Justification radio button group determines where the text is aligned on the button.

Try it now: Accept the default justification so that the text will be centered.


Top of page

x
Trigger, Functions

You specify a function to be performed or a built-in Winform system action to be called when the application user clicks the button. (Functions are referred to as cases in the Winform Painter.) To specify a system action, you press PF5 or click Cases to display a list of system actions and existing functions. After you select the desired system action, the Painter copies your choice to the Trigger field.

To specify an existing function, press PF5 or click Cases to display a list of system actions and existing functions. After you select the desired function, the Painter copies your choice to the Triggers field and assigns that function to the button.

To specify a new function, type the name of the function into the Triggers field.

Try it now: For the tutorial, you must specify a new function, so type PrevCar in the Trigger field.


Top of page

x
Shortcut Key Field; PFKeys

The Shortcut entry field enables you to specify a function key that users can press to click the button, thereby saving keystrokes. If you wish to assign a shortcut key, first determine which keys are available by clicking PFKeys. This displays a list of the function keys (within this Winform) already assigned to buttons and to form-level triggers.

Try it now: Select PF1 in the PF Keys dialog box and then click OK to confirm your choice.

The Painter copies the selected key name to the Shortcut key field and later (upon closing the Button dialog box) assigns PrevCar (your trigger).

You can change the values assigned to other function keys—for example, moving a default system action to a different key—by selecting the Actions option from the Forms menu.


Top of page

x
Default Button

In some Winforms, one command button is the default. You can click the default button quickly by pressing Enter. On terminals that support color, the default button is the color of the terminal's unprotected high intensity field attribute. It is helpful to make the most frequently used button—for example, the OK button—the default.

Try it now: Leave the Default attribute unchecked, as you do not want this button to be the default.


Top of page

x
Border

This attribute displays a border around the perimeter of the button. This is useful if your terminal emulator does not support highlighting.

Try it now: Accept the default value of no border, as you do not want these buttons to have borders.


Top of page

x
Object Name

Try it now: Accept the default name.

When you are finished specifying in the Button dialog box, it should look similar to the following:

Try it now:

  1. Click OK to confirm your work and close the dialog box.

    The Painter displays a message that the PrevCar function (which you had specified as the button's trigger) does not exist and asks if you want the Painter to create the function.

  2. Click the Create button.

    The Painter automatically generates an empty PrevCar function in the Maintain procedure.

This generated function (consisting of CASE and ENDCASE commands) serves as a temporary placeholder while you continue to develop the application.

The Painter generates code when you save your work. To demonstrate what the Painter produces, save your work by selecting the Save option from the File menu.

Try it now:

  1. Place the cursor on the button you just created and press PF12 to edit the button. When the Button dialog box opens, press PF6 to display the PFKeys list.

    Notice that PF1 now displays the button's trigger. (Use PF11 and PF10 to scroll the display to see the entire trigger).

  2. Click Cancel twice to close the PFKeys and Button dialog boxes.

Top of page

x
Adding Additional Buttons and Triggers

Now you will add three additional command buttons to the Winform. Select the Button option from the Objects menu for each one, and supply the following values:

Try it now: Start the second button in row 20, column 24 and end it in row 20, column 39.

  1. Enter Next Car F2 as the button's text.
  2. Type NextCar in the Trigger field.
  3. Select PF2 for the shortcut key.
  4. Accept the defaults for Justification, Border, Default, and Object Name.
  5. Click OK to close the dialog box.
  6. When the Painter notifies you that the NextCar function does not exist, click Create to generate an empty function.

Try it now: Start the third button in row 20, column 43, and end it in row 20, column 58.

  1. Enter Quit F3 as the button's text.
  2. Supply a value for the Trigger field by clicking the Cases button and selecting the exit system action. Select PF3 for the shortcut key. Accept the defaults for Justification, Border, Default, and Object Name. Click OK to close the dialog box.
  3. You may see the following message: This key is already assigned to a system action. Do you want to override it? You can select OK.

Try it now: Start the fourth button in row 20, column 62, and end it in row 20, column 77.

  1. Enter Done F4 as the button's text.
  2. Supply a value for Trigger by clicking Cases and selecting the close system action.
  3. Select PF4 for the shortcut key.
  4. This will be the default button, so select the Default check box.
  5. Accept the defaults for Justification, Border, and Object Name. Click OK to close the dialog box.

The Winform now displays four buttons:


Information Builders