UpPreviousNext

Initializing Resources at Run Time

Using variables as resource values

The simplest way to be able to set resources at run time is to use variables as resource values. Builder Xcessory provides three easy methods of using variables as resource values:

· Constants

· Identifiers

· Expressions

Constants

Constants are Builder Xcessory representations of compile-time constants, that is, #defines . When setting a resource value, select Constant from the Resource Placement menu to the right of the Extended Editor button. You are presented with a choice of constants that you've already defined, and <New>. Choosing <New> brings up the Constant Editor with which you can define a new constant. Builder Xcessory includes this definition in the generated source code.

Constant Manager

You can work with your constants by using the Constant Manager (select Constants from the Browser Managers menu). Refer to Constant Manager for more information.


Note: Because constants have values, using them has an immediate effect in Builder Xcessory. Whenever you change the value of a constant with the Constant Editor, all resources that use the constant are immediately updated.

Identifiers

Identifiers are variables that are valid within the scope of the creation routine. When setting a resource value, select Identifier from the Resource Placement menu to the right of the Extended Editor button. You are presented with a choice of identifiers that you have already defined, and <New>.

Choosing <New> brings up the Identifier Editor, with which you can define a new identifier:

 

Identifier Editor


Note: You must declare your identifiers in the application code, either in a user code block, or in an include file. You must also be sure that the identifier is declared prior to the creation of the object that references it.

Identifiers are not necessarily simple variables. You can define an identifier that is a call to a function or a method, with the appropriate return type. You can work with your identifiers by using the Identifier Manager (select Identifiers from the Browser Managers menu). See Identifier Manager for more information.


Note: Because identifiers are given values only at run time, modifying an identifier with the Identifier Editor has no immediate effect on your Builder Xcessory application.

Expressions

Expressions can be used to specify an integer value for a resource. Type the expression into the value field or in the Integer Editor, as appropriate. The Placement Menu changes to reflect the presence of an expression. Expressions cannot be over-ridden by the X resource manager at run time. In this way they are functionally equivalent to Code Placement.

The syntax for a Builder Xcessory expression is:

expression ::= integer_value
| constant_name
| expression + expression
| expression - expression
| expression * expression
| expression / expression
| ( expression )
| - expression

Expressions are evaluated from left to right. Standard order of precedence is enforced for binary operator expressions.


Note: If an expression depends on a Constant that is cut or deleted (with the Constant Manager), the expression is converted to its previously evaluated value, and written out as an integer. The Placement Menu is changed from Expr to Code to indicate this.

Callbacks with XtSetValues Calls

You can dynamically change a resource value using the X Toolkit call, XtSetValues. Builder Xcessory includes the predefined callback BxSetValuesCB, which takes the following string as its parameter:

"<instance_name>.<resource>=<value>
<instance_name>.<resource>=<value>
...
<instance_name>.<resource>=<value>"

When the callback is called, the resources of the designated object are set to the specified values by using the function XtSetValues.

Example

The following example demonstrates a simple use of BxSetValuesCB:

1. Create a BulletinBoard with two PushButton children.

2. Set the activateCallback resource of pushButton to BxSetValuesCB("bulletinBoard.background=red").

3. Set the activateCallback resource of pushButton1 to BxSetValuesCB("bulletinBoard.background=white").

4. Enter Play Mode(Browser:View).

5. To test the interface, click the PushButtons.

The BulletinBoard toggles between red and white as each call to BxSetValuesCB resets the background resource.

Note: Use unique instance names for objects that are referenced by callbacks. Predefined callbacks rely on the instance name remaining the same each time the widget is created, and the default instance names assigned by Builder Xcessory may change when you edit the instance hierarchy.
UpPreviousNext