ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Editors / Window editor and page editor
  • 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
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
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.
WEBDEV - Server codeWindowsLinux Data persistence is only achieved through programming. The information is stored in a browser cookie.
How to?

Enabling or disabling the persistence of a control in a window

To enable or disable the persistence of a control in a window:
  1. Open the control description window.
  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:
    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.
    • 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:
    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 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 Combo Box control
    // or code 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, username, storage of password, etc.)

    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 parameter value.
    // 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 uses 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 through programming with the following functions:
    DeleteParameterDeletes a parameter (or a set of parameters) saved either by SaveParameter, or automatically via the persistence of data in the controls.
    InitParameterInitializes the management of persistent values.
    LoadParameterReads a persistent value.
    SaveParameterSaves a persistent value in the registry or in another file specified by InitParameter.
    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 version required
    • Version 9
    This page is also available for…
    Comments
    Click [Add] to post a comment

    Last update: 06/22/2023

    Send a report | Local help