|
|
|
|
|
- Overview
- How to?
- Enabling or disabling the persistence of a control in a window
- Operating mode
- Studying the operating mode
- Setting
- Advanced operating mode
- Storing the global variables of a project
- Implementation
- Optimization
- Storing the global variables of a project
- Optimization
- Managing the persistence of data with the WLanguage functions
The data persistence is used to store the value typed by the user. When the user enters a value in a window control, this value will be displayed in the control next time the window is opened. This feature is useful when entering a login, performing searches, using semi-constant parameters, for default choices, ... This feature is available for all the editable controls. This feature is also available to select values in a Radio Button or Check Box control.
Enabling or disabling the persistence of a control in a window To enable or disable the persistence of a control in a window: - Open the control description window.
- On the "Details" tab, check (or uncheck) "Store the value".
By default, the values of persistent controls are stored in the registry (or the equivalent file on the runtime platform). For example: - In Android, the persistent values are saved in the Shared Preferences of the application.
- In iOS, the persistent values are stored in the parameters of the application ("NSUserDefault").
Studying the operating mode When the mechanism for control persistence is enabled: - The content of the control is strored when closing the application.
This information is stored in the registry, in the following key: "HKEY_CURRENT_USER\Software\<Company>\<Project Name>". This key is returned through programming by ProjectInfo. - During the next application start, the persistence mechanism restores the stored controls in their previous status. This restore operation is performed between the declaration code of the window and the initialization code of the window.
Therefore, the assignment of a control value is performed in the following order: - Value defined in the "Content" tab of the control description.
- Running the initialization code of the control. This code can initialize and modify the initial value of the control.
- Persistent value (saved in the registry, in a parameter file, ...). If a persistent value was defined for the control, this value is assigned to the control.
- Running the initialization code of window. This code can initialize and modify the value assigned to the control.
Furthermore, to keep the compatibility with the existing operating mode of the application: - the processes for modifying the controls "automatically" assigned are run.
- the selection codes of List Box and Combo Box controls are run.If the process for modifying or selecting the control must not be run, its execution can be conditioned as follows:
In this case, the rest of the process is not run if the call to this code is triggered as soon as the window is opened, when restoring the stored values. Setting The persistence information is stored in the registry (or the equivalent file on the runtime platform). The method and location of this information can be modified by InitParameter. This function accepts two parameters: - The method for storing the data:
- Document in XML format (not available in Mobile version).
- Configuration file (.ini).
- Registry.
- String in XML format (to be sent by socket or HTTP protocol for example).
- The location corresponding to the method specified in the first parameter (path of XML document, path in the registry or path of configuration file).
Example:
InitParameter(paramIni, "C:\temp\MaConfig.ini")
Reading and saving persistence data remains the same: only the storage method (and location) is modified. Storing the global variables of a project The persistence mechanism is not only used to store the controls, it is also used to store the variables or any other information required by an application. There is no need to "manually" manage a configuration file to store the content of the global variables of a project (data path, date of last connection, username, storage of password, etc.) Implementation - The name of the parameter to restore (logical name), for example the name of the corresponding variable.
- The default value of the parameter (if this parameter has never been saved or used).
gnNbLancement = LoadParameter(CS_NB_LANCEMENT)
gdDateDernierLancement = LoadParameter(CS_DATE_LANCEMENT)
ghHeureDernierLancement = LoadParameter(CS_HEURE_LANCEMENT)
There's no need to manage the type of parameter: the type of parameter is entirely managed by the persistence mechanism (no need, for example, to use the Val function to retrieve a Numerical value). - The name of the parameter to save (logical name). This name is used in LoadParameter.
- The parameter value.
SaveParameter(CS_NB_LANCEMENT, gnNbLancement)
SaveParameter(CS_DATE_LANCEMENT, gdDateDernierLancement)
SaveParameter(CS_HEURE_LANCEMENT, ghHeureDernierLancement)
The information stored by SaveParameter is stored by using the method and location specified by InitParameter (therefore, this information is stored in the registry by default). Note: It is of course possible to use several backup methods and/or files within a single application. Storing the global variables of a project An optimization may be required when the application performs long processes. Indeed, the modification codes of "restored" controls are run. If one of these controls contains a potentially long code, it may be interesting not to run all the modification codes while restoring the controls. Example: Multi-criteria search window that uses the persistence mechanism - During the first startup, the controls have no stored value, the operating mode is "as usual".
- At the end of the application, the persistence mechanism stores the search criteria selected by the user.
- When starting the application, the stored controls are restored and the modification codes of controls are run.
- If these modification codes trigger the execution of the search (common case for a radio button), the search will be performed with different criteria for each stored control! This operation can be very long according to the searches performed.
Optimization In these special cases, all you have to do is "disable" the potentially long processes while they are automatically restored. You have the ability to use the following method: - Declaring a global window variable (boolean type) in the relevant window.
GLOBAL
gbRestaurationEnCours is boolean
- Initializing this variable to "True" in the declaration code of the window.
gbRestaurationEnCours = True
- Adding a test on this variable in the potentially long processes. If this variable is positioned to "True", the process is not performed (the controls are currently restored by the persistence mechanism).
IF gbRestaurationEnCours = True THEN RETURN
...
- Assigning this variable to "False" at the beginning of the initialization code of the window to restore the standard operating mode of the application.
gbRestaurationEnCours = False
Managing the persistence of data with the WLanguage functions The persistence of data can also be managed through programming with the following functions:
Esta página también está disponible para…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|