Working with Forms

The Form class provides some methods that allow you to change the appearance or behavior of items on a form.

Getting a reference to the Form object

In order to use the methods, you must get a reference to the form object. The Window class has a method to get the reference to its associated form:

Once you have the reference to the form object, you can call any of the object methods for the Form class
LET mywin = ui.Window.getCurrent()
LET f1 = mywin.getForm() -- get reference to form 
-- call a Form class method   
CALL f1.loadActionDefaults("mydefaults")

See The Form class section of the Genero Business Development Language User Guide for a complete list of methods.

Specifying the name of a form item

Some of the methods in the Form class require you to provide the name of the form item. The name of the form item in the ATTRIBUTES section of the form specification file corresponds to the name attribute of an element in the runtime form file. For example:

Note: Formfield names specified as FORMONLY (FORMONLY.pflag) are converted to lowercase (formonly.pflag).

Although Genero BDL is not case-sensitive, XML is. When Genero creates the runtime XML file, the form item types and attribute names are converted using the CamelCase convention:

If you use classes or methods in your code that require the form item type or attribute name, respect the naming conventions.

Changing the text, image, and style properties of a form item

Some methods of the Form class allow you to change the value of specific properties of form items.

Call the methods using the reference to the form object. Provide the name of the form item and the value for the property:

The style mystyle is an example of a specific style that was defined in a custom Presentation Styles XML file, customstyles.4st. This style changes the text color to blue:
<Style name=".mystyle" >
  <StyleAttribute name="textColor" value="blue" />
</Style>
By default, the runtime system searches for the default.4st Presentation Style file. Use the following method to load a different Presentation Style file:
CALL ui.interface.loadStyles("customstyles")

See Presentation styles in the Genero Business Development Language User Guide for additional information about styles and the format of a Presentation Styles file.

Example 2

01 MAIN
02  DEFINE mywin ui.Window,
03          f1    ui.Form 
04   CALL ui.interface.loadStyles("customstyles")
05  OPEN WINDOW w1 WITH FORM "testform"
06  LET mywin = ui.Window.getCurrent()
07    CALL mywin.setText("test")
08    LET f1 = mywin.getForm()
09  MENU
10    ON ACTION changes 
11      CALL f1.setElementText("lb1", "goodbye")
12      CALL f1.setElementText("quit", "leave")
13      CALL f1.setElementImage("quit", "exit.png")
14      CALL f1.setElementStyle("lb1", "mystyle")
15    ON ACTION quit 
16      EXIT MENU
17  END MENU
18 END MAIN
This figure is a screenshot of a form where ui.Form methods are used to change the text for the label and button, specify an image for a button, and specify a style for a label.

Figure 1. Display on Windows™ platform after the changes button has been clicked.