PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • How to proceed?
  • 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
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Overview
The persistence of data allows you to store the value entered by the user.
When the user enters a value in a window control, this value will be displayed in the control during the next window opening. 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.
Versions 15 and later
Android The persistence of data is available in Android.
New in version 15
Android The persistence of data is available in Android.
Android The persistence of data is available in Android.
Versions 17 and later
Universal Windows 10 App The persistence of data is available in Windows Phone.
New in version 17
Universal Windows 10 App The persistence of data is available in Windows Phone.
Universal Windows 10 App The persistence of data is available in Windows Phone.
Versions 18 and later
Android Widget The persistence of data is available in Widget Android mode.
Universal Windows 10 App The persistence of data is available in Windows Store apps mode.
New in version 18
Android Widget The persistence of data is available in Widget Android mode.
Universal Windows 10 App The persistence of data is available in Windows Store apps mode.
Android Widget The persistence of data is available in Widget Android mode.
Universal Windows 10 App The persistence of data is available in Windows Store apps mode.
Versions 19 and later
iPhone/iPad The persistence of data is available in iPhone/iPad.
New in version 19
iPhone/iPad The persistence of data is available in iPhone/iPad.
iPhone/iPad The persistence of data is available in iPhone/iPad.
How to proceed?

Enabling or disabling the persistence of a control in a window

To enable or disable the persistence of a control in a window:
  1. Display the description window of control.
  2. In 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:
  • AndroidAndroid Widget In Android, the persistent values are saved in the Shared Preferences of the application.
  • iPhone/iPad In iOS, the persistent values are stored in the parameters of the application ("NSUserDefault").
  • Universal Windows 10 App In Windows Phone, the persistent values are saved in the parameters of the application ("Isolated Storage Settings").
WINDEV Note: This mechanism can be implemented by the user via "Store" from the popup menu of the controls (AAF).
Operating mode

Studying the operating mode

When the mechanism for control persistence is enabled:
  • The content of the control is strored when closing the application.
    WINDEV This information is stored in the registry, in the following key: "HKEY_CURRENT_USER\Software\<Company>\<Project Name>". This key is returned by programming by ProjectInfo.
  • During the next start of the application, 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:
  1. Value defined in the "Content" tab of the control description.
  2. Running the initialization code of the control. This code can initialize and modify the initial value of the control.
  3. 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.
  4. Running the initialization code of the 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:
// Code for selecting a row in a combo box or for modifying a control
IF OPENING THEN RETURN
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:
// Use a configuration file (.ini)
InitParameter(paramIni, "C:\temp\MyConfig.ini")
The reading and the backup of persistence data remain identical: only the storage method (and the localization) is modified.
Advanced operating mode

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, user name, storage of password, ...).

Implementation

You must use LoadParameter and SaveParameter.
LoadParameter accepts two parameters:
  • 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).
// Load an integer parameter
gnNbStartups = LoadParameter(CS_NB_STARTUPS)
// Load a date parameter
gdLastStartupDate = LoadParameter(CS_STARTUP_DATE)
// Load a time parameter
gtLastStartupTime = LoadParameter(CS_STARTUP_TIME)
There is 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 Val to retrieve a numeric value).
SaveParameter also accepts two parameters:
  • The name of the parameter to save (logical name). This name is used in LoadParameter.
  • The value of the parameter.
// Store an integer parameter
SaveParameter(CS_NB_STARTS, gnNbStarts)
// Store a date parameter
SaveParameter(CS_START_DATE, gdLastStartDate)
// Store a time parameter
SaveParameter(CS_START_TIME, gtLastStartTime)
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: Several methods and/or several backup files can be used in the same application.
Optimization

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: Case of a window for multi-criteria search that is using the persistence mechanism
  1. During the first startup, the controls have no stored value, the operating mode is "as usual".
  2. At the end of the application, the persistence mechanism stores the search criteria selected by the user.
  3. When starting the application, the stored controls are restored and the modification codes of controls are run.
  4. 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:
  1. Declaring a global window variable (boolean type) in the relevant window.
    // Declaration code of the window
    GLOBAL
    gbRestoreInProgress is boolean
  2. Initializing this variable to "True" in the declaration code of the window.
    // Declaration code of the window
    gbRestoreInProgress = True
  3. 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).
    // Potentially long process
    IF gbRestoreInProgress = True THEN RETURN
    ...
  4. Assigning this variable to "False" at the beginning of the initialization code of the window to restore the standard operating mode of the application.
    // Initialization code of the window
    gbRestoreInProgress = False
Managing the persistence of data with the WLanguage functions
The persistence of data can also be managed by programming with the following functions:
Versions 09 and later
DeleteParameter
New in version 09
DeleteParameter
DeleteParameter
Deletes a parameter (or a set of parameters) saved either by SaveParameter, or automatically via the persistence of data in the controls.
Versions 09 and later
InitParameter
New in version 09
InitParameter
InitParameter
Initializes the management of persistent values.
Versions 09 and later
LoadParameter
New in version 09
LoadParameter
LoadParameter
Reads a persistent value.
Versions 09 and later
SaveParameter
New in version 09
SaveParameter
SaveParameter
Saves a persistent value in the registry or in another file specified by InitParameter.
WINDEV Notes:
  • To automatically save all the persistent controls found in a window, use ExecuteAAF.To automatically save all the persistent controls found in a window, use AAFExecute (or ExecuteAAF).
  • DisableAAF is used to disable the persistence of controls. AAFDisable (or DisableAAF) is used to disable the persistence of controls.
Related Examples:
WD Persistence Training (WINDEV): WD Persistence
[ + ] This example presents the use of InitParameter, LoadParameter and SaveParameter.
These functions are used to configure the backup of controls, variables and other parameters.
This example is divided into three parts:
- The configuration
- The manual management of variables (SaveParameter and LoadParameter)
- The optimization
1°) Configuration

The configuration window enables you to modify the location of the backup of parameters (registry, INI file, XML file) as well as its path (registry key or file path).
2°) Manual management of the variables
The manual management enables you to save the content of the variables via SaveParameter and to restore them via LoadParameter. Each parameter is identified by a name. These values are saved at the location defined in the configuration window.
3°) The optimization
This window explains how to optimize your code to avoid the slowness caused when the saved values are restored. Indeed, when restoring the value of a control, its modification code is run. If you have long processes (queries with parameters for instance), this window shows you how to speed up the loading of the window.
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment