Quick Tutorial - Using App Settings

Description

This tutorial shows how to create variables persisted between BrightForms instances.

Resources

Introduction

In BrightBuilder projects, data is stored and accessed in memory through variables, which are present on differing levels throughout the project. With each variable there is a concept of scope; where the variable is unique and in effect, and therefore accessible. In BrightBuilder, variables may have expression, form or global scopes.

The scope also effectively dictates the variable’s lifetime, with local variables being in effect only through the current expression, form variables from when the form opens and closes, and global variables from when the project is executed in BrightForms to when it is closed.

However, what if these values need to be saved or reused the next time BrightForms opens? This is where App Settings may be used when developing projects.

App Settings work and act similarly to Global Variables in BrightBuilder, as they may be accessed throughout the project’s forms and expressions. However, they differ as instead of being persisted in memory, they are persisted to file, allowing them to be accessed and retrieved even when BrightForms is closed.

Storing data like variables, App Settings contain the following information:

App settings also differ from Global Variables as they are defined with another field:

If the app setting is not found, it is created and initialised with this value on project execution. Once created and assigned, changing this value field will have no effect as long as the app settings file continues to exist in the system. To reset the app settings of a project, simply locate and remove the project’s .bsa file, which stores these values. This file is located in BrighForms’ projects directory.

Creating App Settings

App Settings are located in the properties of a project, which can be accessed either by right clicking the project and selecting ‘Properties’, or via the properties panel of BrightBuilder while the project is selected.

This property may then be clicked, bringing up App Settings dialog. Initially, in a new project, it will be empty, with values able to be added by right clicking, and selecting ‘Add New Setting’. This will create a new setting, ‘Setting1’ of type String, which may then be edited via double clicking each cell.

Once these are edited and the OK button is pressed, the settings created may be used throughout the project, such as through the data source tree.

Exercise

The file to be edited is a simple login screen which saves the username of the last user to click the ‘login’ button, and the time this event takes place.

 

Currently, the application loads from two global variables (global.VarLastUser and global.VarLastTime) with the expression eOnOpen on startup. Once the login button is clicked, buttonLogin_Click writes the username entered and the time pressed to the two global variables, and then the eOnOpen expression is called again, showing the new values. This may be repeated, with previous values overwritten.

However, when BrightForms closes and is re-opened, the values are no longer saved. Thus it is restricted by BrightForms’ sessions.

This doesn’t need to be the case if we use App Settings. Edit the application such that the last login data is displayed once saved, even when it closes and is opened again.