PC SOFT

WINDEV的在线文档

  • Overview
  • How to proceed?
  • Enabling or disabling the persistence of a control in a window
  • Operating mode
  • Analyzing 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
文档页面当前正在翻译。对于此延迟我们深表歉意。
您可以自愿地帮助我们翻译您想要的文档段落,然后只需通过以下地址与我们联系:info@cn.windev.com
产品
WinDevWebDev-服务器代码WebDev-浏览器代码WinDev Mobile报表和查询
平台
WindowsLinuxWindows MobileWindows PhoneWindows Store appsAndroidAndroid Widget iPhone/iPad
语言
JavaPHPAjax用户代码(MCU)外部语言
数据库
HFSQLHFSQL Client/Server存储过程HF 5.5OLE DBODBC本地访问

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 opening of the window. 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.

18版本和更高版本
WinDevWindows Store apps The persistence of data is available in Windows Store apps mode.
18新版本
WinDevWindows Store apps The persistence of data is available in Windows Store apps mode.
WinDevWindows Store apps The persistence of data is available in Windows Store apps mode.

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 the 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:
    WinDev Note: This mechanism can be implemented by the user via "Store" from the popup menu of the controls (AAF).

    Operating mode

    Analyzing 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 项目信息.
    • During the next startup 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 modification codes of the controls "automatically" assigned are run.

    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 初始化参数.

    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 the XML document, path in the registry or path of the configuration file).
    Example:
    // Use a configuration file (.ini)
    初始化参数初始化参数.INI格式"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 加载参数 and 保存参数.

    加载参数 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加载参数CS_NB_STARTUPS
    // Load a date parameter
    gdLastStartupDate加载参数CS_STARTUP_DATE
    // Load a time parameter
    gtLastStartupTime加载参数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 数值 to retrieve a numeric value).

    保存参数 also accepts two parameters:

    • The name of the parameter to save (logical name). This name is used in 加载参数.
    • The value of the parameter.
    // Store an integer parameter
    保存参数CS_NB_STARTUPSgnNbStartups
    // Store a date parameter
    保存参数CS_STARTUP_DATEgdLastStartupDate
    // Store a time parameter
    保存参数CS_STARTUP_TIMEgtLastStartupTime

    The informations stored by 保存参数 is stored by using the method and the location specified by 初始化参数 (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 variable of boolean type in the relevant window.

    // Declaration code of the window
    全局
    gbRestoreInProgress布尔型

    2. Initializing this variable to "True" in the declaration code of the window.

    // Declaration code of the window
    gbRestoreInProgress

    3. Adding a test onto 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
    如果gbRestoreInProgress,那么返回
    ...

    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

    Managing the persistence of data with the WLanguage functions
    The persistence of data can also be managed by programming with the following functions:
    09版本和更高版本
    加载参数
    09新版本
    加载参数
    加载参数
    Reads a persistent value.
    09版本和更高版本
    初始化参数
    09新版本
    初始化参数
    初始化参数
    Initializes the management of persistent values.
    09版本和更高版本
    保存参数
    09新版本
    保存参数
    保存参数
    Saves a persistent value in the registry or in another file specified by 初始化参数.
    09版本和更高版本
    删除参数
    09新版本
    删除参数
    删除参数
    Deletes a parameter (or a set of parameters) saved either by 保存参数, or automatically via the persistence of data in the controls.

    WinDev Notes: