Allows you to view constants to help you apply resource values to objects. Select Constants from the Browser Managers menu to display the Constant Manager:
Constant Manager File Menu
Select File from the Constant Manager menu bar, either with the mouse or with a mnemonic, to display the Constant Manager File menu:
Constant Manager Edit Menu
Select Edit from the Constant Manager menu bar, either with the mouse or with a mnemonic, to display the Constant Manager Edit menu:
Constant Manager Edit Menu
The following sections describe the options available from the Edit menu.
Constant Editor
Select Edit Constant from the Constant Manager Edit menu to display the Constant Editor:
Type
Specify the type of the constant using the Type text field and its associated combination box. You may specify any of the following UIL data types:
Note: Respective C data types are listed in the Type Manager.
Value
Specify the resource value of the constant in the Value text field, or by using the associated extended editor (accessible by pressing the (...) button).
Reference Count
Reference Count enumerates the number of times the constant is referenced in the current interface and in the Builder Xcessory. The type of the constant may not be changed as long as this value is greater than zero. The notation Palette = n means that there are n references to the constant in collections on the Palette.
UIL Scope
Set the scope of the constant to either Private or External in the UIL output file:
- Can only be referenced in the UIL module containing the constant value declaration. The value is directly incorporated into anything in the UIL module that references the declaration.
- Stored in the UID (compiled UIL) file as a named resource, and therefore can be referenced by name in other UIL files. This is the same as an "exported" UIL value.
Note: Scope affects only UIL files generated by Builder Xcessory.
Output File Option Menu
The Output File Option Menu allows you to specify the file to which the constant will be written when Builder Xcessory generates UIL. See File Placement for more detailed information.
Using constants
You use constants in different ways, depending on whether you are generating UIL or C code.
Generating UIL
When generating UIL code, you can use constants to fetch the resource value at runtime. UIL automatically translates the data type of the constant to that of the resource value. This saves you the trouble of explicitly specifying the X, Xt, and Motif calls in the code.
For example, if you create a constant named COLOR_CONSTANT with the value "RED", the defs-c.h file will contain the line:
while the UIL file would contain the line:
If you wanted to fetch the value in the file main-uil.c, you would include in that file the line:
Generating C
When generating C, you can use constants for the following tasks:
· Define named resources up front, similar to the definition of constants in the header of a program.
Referencing constants
Constants which have been defined may be referenced in various places in the Builder Xcessory.
Resource Editor
Enter a constant as a resource value in a resource's text field, or from the Const pop-down list off the resource placement options menu, in the Resource Editor. Refer to Resource Editor for a detailed description of the Resource Editor.
If a widget's resource value depends on a constant that is subsequently Cut from the Constant Manager, then the widget's resource is changed from Constant to Code, and the resource value is set to the current value of the constant.
Styles
Use a constant as part of a style definition by entering the constant name in the appropriate text field on the Style Editor. Refer to Style Editor for detailed information.
Extended Editors
Select a constant from any of the Builder Xcessory extended editors. Selecting the Constant radio button displays a combination box which contains the names of all constants of the appropriate type. Refer to Extended Editors for a description of each of the extended editors.
Expressions
In the previous sections, a constant of type Integer may be used as part of an expression. For more information, refer to Expressions .
Example
This example describes how to apply a constant to the background resources of the widget instances in your interface:
Creating the constant
To create the constant, perform the following steps:
1. Select Constants from the Browser Managers menu.
2. Select Create Constant from the Constant Manager Edit menu.
3. Double-click on the new constant to bring up the Constant Editor.
4. In the Constant Editor, enter the name OK_LABEL in the Name text field.
5. Click the arrow button to display the Type combination box, and select Compound String. Click the (...) button to the right of the Value textfield to display the Compound String Editor.
6. Specify the value "OK" (without quotation marks) in the Compound String Editor text area. Refer to Compound String Editor for more detailed information about the Compound String Editor.
7. Click the Apply button on the Compound String Editor to apply the string value to the constant. Dismiss the Compound String Editor. The value is entered in the Constant Editor Value text field.
8. Click the Constant Editor Apply button to create the constant OK_LABEL, displayed in the Constant Manager.
Referencing the constant
To reference the constant, perform the following steps:
1. Create a push button and update the Resource Editor.
2. Click the (...) button to the right of the labelString resource to display the Compound String Editor.
3. Click the Constant toggle to the right of Resource Placement at the bottom of the Compound String Editor. This displays a dialog with a textfield and an arrow button.
4. Click the arrow button to the right of the Constant Name text field to view all existing constants of the same type as the resource labelString (type: compoundString).
5. Select OK_LABEL and click the Apply button at the bottom of the dialog to apply the constant as the value of the push button's labelString resource. If you go back to the Constant Editor, you will notice that the Reference Count for OK_LABEL has been changed.
Note: If the Constant Editor is visible when the constant is applied to or deleted from a resource, then the Reference Count will be updated by clicking the Constant Editor Reset button.