Top
PowerCOBOL V11.0 User's Guide
FUJITSU Software

10.2.2 Working with Properties

Working with Properties in the PowerCOBOL development environment is somewhat similar to working with Methods. Highlighting the name of a control in the editor such as a command button and right clicking on it will allow you to select a list of available properties for that particular control such as:

Figure 10.5 A list of available properties for a CommandButton control

As you can see, there may be many different properties available for a particular type of control. Most properties are available at both design time and runtime. For example, you could have changed a CommandButton's background color (the BackColor property) when you were painting it on a form in the form editor before you built the project. You could also change the BackColor property at runtime by moving a new color value to it such as:

Move POW-COLOR-BLUE To "BackColor" Of ButtonOK.

Note that some properties contain sub-properties and the syntax requires an additional level of direction. For example, the Font property contains sub-properties named Style, Size, Bold, Charset, Italic, Strikethrough and Underline. If you wanted to change the size of the current font in a textbox control named CmText1 to 10 points, you might be temped to code something like:

Move 10 to "Font" Of CmText1. 

Unfortunately, the above code will generate a compile error if you attempt to build it. The reason for this error is because PowerCOBOL has no way of knowing which of the sub-properties of Font you want to direct the value 10 to. The proper code to set the font size to 10 points would instead be:

Move 10 To "Size" Of "Font" Of CmText1.

Remember to use the on-line help system to look up properties to determine if they have sub-properties and additionally to determine the valid type of data to move to them.

Some properties are available to set only at design time, such as determining if a form will have a title bar. Other properties are available only at runtime. Some properties are read only at runtime. You should become more familiar with these aspects of properties as you gain experience with PowerCOBOL.

Also note that PowerCOBOL supplies a number of system constants to use for setting properties. A color code for a background color, for example, is a bit pattern. Instead of being forced to remember and code bit patterns for colors, PowerCOBOL provides a number of constants such as POW-COLOR-BLUE that you can reference in your code. Look up Constants in the on-line help system to get a feel for what constants are available to you.

Using properties effectively can add a great deal of usability to your applications. For example, let's suppose you write an event procedure wherein if a user clicks on a CommandButton on a form, you want to print the current form. The code for this event might look like:

INVOKE CmPrint1 "PrintForm".

This code should work as expected when the user clicks on the CommandButton it is associated with. A potential problem exists however, because the nature of printers is that they are not instantaneous.

If a user clicks on the CommandButton, and the print process does not begin immediately, he or she may be inclined to click on the CommandButton again and again. This causes multiple click events and the PrintForm method will be called multiple times (once for each user click on the CommandButton).

A simple programming technique to prevent this from happening is to disable the command button after it is pushed, print the form, and then enable the CommandButton after the form has printed. Using the Enabled property of the CommandButton will do just the trick as follows:

Move POW-FALSE To "Enabled" Of CmCommand1.
INVOKE CmPrint1 "PrintForm".
Move POW-TRUE  To "Enabled" Of CmCommand1.

You should find working with properties and methods straightforward and intuitive as you spend more time creating PowerCOBOL applications.