Built-in variables: styles
The variable styles stores in a multi-variant application the names of all currently active style members. Please note, the variable is declared with the homonymous styles data type.
Declaration
styles styles
Discussion
In your project you can define several style members, one for every mode and device configuration your application should support. Then at the runtime, you activate individual styles by adding the corresponding style member names to the built-in variable styles. Similarly to deactivate styles, you remove the names of the corresponding style members from the styles variable. Assuming, in your project you have defined style members called HiRes, NightMode and DebugMode, then the following operation would deactivate the styles DebugMode and HiRes and activate the style NightMode:
// Assuming an initial situation styles = [ HiRes, DebugMode ]; // styles = [ HiRes, DebugMode ] // Deactivate the DebugMode and the HiRes style styles = styles - [ DebugMode, HiRes ]; // styles = [] // Activate the NightMode style styles = styles + [ NightMode ]; // styles = [ NightMode ]
The modification of the styles variable affects only the subsequent accesses to multi-variant classes, autoobjects, constants, font and bitmap resources. It has no effect on already evaluated expressions. In other words: the once instantiated object of a multi-variant class will not change its content nor its behavior when you afterwards switch the styles. Assuming, your project contains a multi-variant autoobject Drivers::DeviceObject depending on the style DebugMode, then the both variables object1 and object2 at the end of the following example will refer to different versions of the original autoobject:
styles = []; // styles = [] var Drivers::DeviceClass object1 = Drivers::DeviceObject; styles = styles + [ DebugMode ]; // styles = [ DebugMode ] var Drivers::DeviceClass object2 = Drivers::DeviceObject; styles = styles - [ DebugMode ]; // styles = [] (again) var Drivers::DeviceClass object3 = Drivers::DeviceObject; trace object1 == object2; // false trace object1 == object3; // true
You can also evaluate the variable styles within expressions wherever an operand of data type styles is allowed. For example, you can store the variable locally or use it in conditions. The following code demonstrates it on the example of how to toggle the NightMode style:
var styles tmp = styles; if ( tmp.contains([ NightMode ])) tmp = tmp - [ NightMode ]; else tmp = tmp + [ NightMode ]; styles = tmp;