AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / Editores / Editor de ventanas y páginas
  • 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
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
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 - Código ServidorWindowsLinux Data persistence is only achieved programmatically. 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. 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:
  • AndroidWidget Android 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").
WINDEV Remark: This mechanism can be set up by the user using the "Store" in the context menu of the controls (AAF) option..
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 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:
  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 de sélection d'une ligne d'un champ Combo 
// ou code de modification d'un champ
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:
// Utilisation d'un fichier de configuration (.ini)
InitParameter(paramIni, "C:\temp\MaConfig.ini")
Reading and saving persistence data remains the same: only the storage method (and location) 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).
// Chargement d'un paramètre de type entier
gnNbLancement = LoadParameter(CS_NB_LANCEMENT)
// Chargement d'un paramètre de type date
gdDateDernierLancement = LoadParameter(CS_DATE_LANCEMENT)
// Chargement d'un paramètre de type heure
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).
SaveParameter also accepts two parameters:
  • The name of the parameter to save (logical name). This name is used in LoadParameter.
  • The parameter value.
// Mémorisation d'un paramètre de type entier
SaveParameter(CS_NB_LANCEMENT, gnNbLancement)
// Mémorisation d'un paramètre de type date
SaveParameter(CS_DATE_LANCEMENT, gdDateDernierLancement)
// Mémorisation d'un paramètre de type heure
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.
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: Multi-criteria search window 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.
    // Code de déclaration de la fenêtre
    GLOBAL
    gbRestaurationEnCours is boolean
  2. Initializing this variable to "True" in the declaration code of the window.
    // Code de déclaration de la fenêtre
    gbRestaurationEnCours = 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).
    // Traitement potentiellement long
    IF gbRestaurationEnCours = 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.
    // Code d'initialisation de la fenêtre
    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:
BorrarParámetroBorra un parámetro (o una set de parámetros) guardado por SaveParameter, o automáticamente a través de la persistencia de datos en los controles.
InitParameterInitializes the management of persistent values.
LoadParameterLee un valor persistente.
SaveParameterGuarda un valor persistente en el registro o en otro archivo especificado por InitParameter.
WINDEV Remarks:
  • To automatically save all the persistent controls found in a window, use AAFExecute.
  • AAFDisable is used to disable the persistence of controls.
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 24/09/2024

Señalar un error o enviar una sugerencia | Ayuda local