The Expression tab of the Properties window makes it possible to control any property of a Page object by means of a Python script, a Database column or a Manual Entry.
IMPORTANT! Expressions are supported in our Business and Pro-Smart editions only!
To control an object property with a script, select the object and enter the Python script in the text box next to the property name. For example, select a text object on the card layout and enter the following script for the Background property of that text object (in this case the script is just a single variable name):
vColor
After pressing Enter, the designer will prompt for a default value for the script variable vColor. Here you can type, for example:
Red
After closing the pop-up window, the background of the text object will be red. The text box where the script was entered will show a red glow to indicate that this value is now controlled by a script. Changing the value of the script variable in the Variables tab of the Properties window, will make the background color of the text object change accordingly.
For any script defined in the Expressions tab, it is important that the result value can be converted to the correct data type. the designer recognizes many text representations, like ‘Red’ in the above example. Please, note that the designer recognizes the standard color names as well as the HTML representation of a 32-bits ARGB color, for example:
#FFFF0000
Scripts can only contain a single line of code. For that reason, it will generally be necessary to define functions in order to program more complex functionality. For the Background property, one can, for example, define the following function in the Functions tab (For more information about Functions, please see the Functions section in this Help file).
def IsValid(s):
if s == 'OK':
return 'Transparent'
else:
return 'Red'
With this function, the script for the Background property can look like
IsValid(vStatus)
If the variable vStatus has the value ‘OK’, the background of the text object will be transparent, and red otherwise.
It is also possible to control the value of a property directly by a database column or manual entry, without the intervention of a script. This can be achieved by dragging and dropping a database column or manual entry from the Data tab of the main window and drop it on the text box in the Expressions tab. Database-column mappings are characterized by a green glow and Manual Entries by a yellow glow.