
An introduction to creating and linking expressions in BrightBuilder, and utilising the data source tree feature.
An expression is a set of operations which can be used to compute and assign values both within and between forms and controls, and to control the flow of execution of the application. They are a flexible tool which can be used to create complex business logic, database operations and other functionality.
Each form has its own set of expressions, and thus expressions are handled within forms with the ‘Expressions’ tab in the workspace.
Located in this tab is an expressions node which handles the switching, creation and modification of a form’s expressions, as well as other features for exportation and manual input within the expressions window. These operations may also be accessed via the expressions toolbar in each expression's tab.
Alternatively, there are shortcuts to create and link expressions such as double clicking a control with an action property, which automatically creates an expression and links it to the default action of the control.
To the left of the expressions pane, you will see one of the major features of BrightBuilder – the Data Source Tree. It provides a simple, easy to use interface with grouped data sources to create expressions, allowing the developer to intuitively construct expressions quickly, without having to look up and memorise system variables, methods and their parameters.
While a text input method is available for advanced users, it is not recommended for beginner users of the application, as all valid expressions can be created easily through the data source tree.
Controls which may be assigned or whose values may be retrieved are located in the Form > Controls folder of the data source tree. Whether or not a value is to be assigned or retrieved is based on where it is dragged and dropped to in the expression window.
A control dragged and dropped on a new line is assumed to be an assignment by default, with the assigned value as ‘???’ – a placeholder for a value. This signifies a value needs to be assigned to it, and as is will not be a valid expression. Values may replace this holder by a drag and drop over it, or if the type is fixed, by a double click.
Constants are values which may not be assigned. The type of a constant is determined by its node in the data source tree. New string, int and double constants may be defined by double clicking on the child of these nodes and assigning a new value with the input dialog, as seen below. Once assigned, double clicking on these defined constants will result in a similar input dialog to rename the field.
References to Variables can be created and accessed similarly to constants, only they can be assigned values, similar to controls. ‘local.<name>’ indicates a variable which is only within the current expression’s scope. As future projects are endeavoured, different types and levels of variables may be encountered, and this is covered in the Bright Software User Manual, and will be explored in future tutorials.
Clicking on a constant or variable within the expression window will locate the constant in the data source tree for reuse.
Another vital component of the expressions tab is the Operator Toolbar, located by default at the bottom of the tab. This can be used to create statement logic, calculations and other operations with the data sources supplied by the data source tree.
An expression can be linked via the properties of a form’s control, such as ‘Action – Click’, or to forms themselves with ‘Action – On Open’ and so forth. The name of the property suggests which action the property refers to.
If an expression is created via double clicking a control in the form layout tab, it is automatically linked to the 'Action - Click' property.
Open the ExprStart.bsp file, and create a new expression linked to the ‘action_btn’ control. Create the expression below using BrightBuilder’s data source tree. It will display a message box welcoming the user.
Expression:
//Display a warm welcome
local.vMsg = "Hello, " & name_field & "!";
Form.MessageBox("Welcome", local.vMsg, MB_OK);
Note, that Form.MessageBox() is a method which will display a message box to the user via the form application object. MB_OK is a system constant for a type of message box. For more information, refer to the Bright Software Object Definitions manual.
The finished application should be similar to ExprFinished.bsp