ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage syntax / Declaring variables
  • Overview
  • Global variable
  • Variables global to a project
  • Variables global to a window
  • Variables global to a page
  • Variables global to a report
  • Variables global to a set of procedures
  • How to use a global variable from a component
  • Global Variable: Syntax
  • Declaring one or more global variables
  • Local variable
  • Local variable: Syntax
  • Declaring one or more local variables
  • Zombie local and global variables
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
Two types of variables are available:
  • Local variable: can only be used in the process in which this variable has been declared.
  • Global variable: can be used in all processes depending on the process in which this variable has been declared.
Important: Do not declare two variables with the same name (in particular, a global variable and a local variable).
Global variable

Variables global to a project

Global variables declared in the "Initialization" event of a project can be used in all the events or processes:
  • of the project.
  • of the window or page (events of the window or page, of its controls and of the associated local procedures).
  • of the report (events of the report, of its controls and of the associated local procedures).
WEBDEV - Server codeWEBDEV - Browser code Availability of variables in browser code:
  • Project global server variables are available in browser codes only for the following types: Boolean, Integer, Real, String.
  • Tip: global variables declared in server code can be used to transmit information to the browser.
  • You have the ability to protect the variable global to the project so that it becomes unavailable on the browser side. To do so, use the Server only attribute when declaring the variable.
    The following syntax must be used:
    NomVariable est un TypeVariable <serveur uniquement>

    or:
    NomVariable est un TypeVariable, serveur uniquement

    Example:
    mavariable is int <server only>
    mavariable1 is int, server only
WEBDEV - Browser code Synchronization of variables in browser code:
  • By default, changes made to global variables in browser code are not carried over to the server.
  • When declaring a global variable, you can request its synchronization between browser and server. In this case the value assigned to a global variable in a browser code, can be retrieved later in a server code. To do so, use the browser synchronized attribute when declaring the variable.
    The following syntax must be used:
    NomVariable est un TypeVariable <synchronisé navigateur>

    or:
    NomVariable est un TypeVariable, synchronisé navigateur

    Example:
    mavariable is int <browser synchronized>
    mavariable1 is int, browser synchronized
WINDEVWINDEV Mobile

Variables global to a window

Global variables declared in the "Global declarations" event of a window can be used in all the events or processes:
  • of the window.
  • of the window controls.
  • of the local procedures associated with the window.
Limits:
  • The global variables of a window cannot be used by its sibling windows.
  • The global variables declared in a child window cannot be used in its parent window.
  • When the window where the variable was declared is closed, this variable cannot be used anymore.
Note: Use of a global variable in a child window of thedeclaration window.
The variables declared global in a window are visible in the child windows of this window in the following cases:
  • If the External keyword is used to declare the variable in the child window.
  • If the variable name is prefixed by the window name.
  • If the variable is passed as a parameter to the child window.
WEBDEV - Server codeWEBDEV - Browser code

Variables global to a page

WEBDEV - Server code Server code
Global variables declared in the "Global declarations" event of a page can be used in all the events or processes:
  • of the page.
  • of the page controls.
  • of the local procedures associated with the page.
When the page where the variable was declared is closed, this variable cannot be used anymore.
Variable availability in Browser code: Server variables global to a page are available in the page's Browser code only for the following types: Boolean, Integer, Real, String.
Tip: global variables declared in server code can be used to transmit information to the browser.
Caution: modifications made to these global variables in browser code are not transferred to the server.
You can protect the page global variable to avoid making it available on the browser. To do so, use the Server only attribute when declaring the variable.
The following syntax must be used:
NomVariable est un TypeVariable <serveur uniquement>

or:
NomVariable est un TypeVariable, serveur uniquement

Example:
mavariable is int <server only>
mavariable1 is int, server only
Synchronization of variables in browser code:
  • By default, changes made to global variables in browser code are not carried over to the server.
  • When declaring a global variable, you can request its synchronization between browser and server. In this case the value assigned to a global variable in a browser code, can be retrieved later in a server code. To do so, use the browser synchronized attribute when declaring the variable.
    The following syntax must be used:
    NomVariable est un TypeVariable <synchronisé navigateur>

    or:
    NomVariable est un TypeVariable, synchronisé navigateur

    Example:
    mavariable is int <browser synchronized>
    mavariable1 is int, browser synchronized
WEBDEV - Browser code Browser code
Global variables declared in the "Page load (onLoad)" event can be used in all the browser events or processes:
  • of the page.
  • of the page controls.
  • of the local procedures associated with the page.
Variable availability in Server code: Browser variables global to a page are not available in the page's Server code.
Tip: global variables declared in browser code can be used to exchange information between different processes running on the browser..
Remarks:
  • The global browser variables cannot be initialized on the declaration line.
  • The global Browser variables can be initialized with the value of a global server variable (for the boolean, integer, real and string types only).
  • We recommend that you disable the "cache" of your browser when developing the WEBDEV application. Indeed, the global variables are translated into JavaScript in ".JS" files. If the "cache" is enabled, the tests of your pages may reload files corresponding to former values of variables.
To disable the cache of your browser (Microsoft Internet Explorer):
  1. Find "Internet options" in one of the menus ("Edit", "Display" or "Tools" according to the version of Internet Explorer).
  2. On the "General" tab, click "Parameters" in the "Temporary Internet Files" section.
  3. Check "Whenever the page is visited".
WINDEVWEBDEV - Server codeiPhone/iPadIOS WidgetMac Catalyst

Variables global to a report

Global variables declared in the "Open" event of a report can be used in all the events or processes:
  • of the report.
  • of the report controls.
  • of the local procedures associated with the report.

Variables global to a set of procedures

Global variables declared in the "Declaration" event of a set of procedures can be used in all the events or processes:
  • of the different procedures in the set.
  • of the current project.

How to use a global variable from a component

Since the purpose of a component is to be stand-alone, no global variable of the project should be used from this one.
However, the recommended method is as follows:
  • create a global variable in the component.
  • in the component, create a procedure used to initialize these global variables.
  • from the "Initialization" event of the project and whenever the value of the global variables of the project is modified, call this procedure to assign a similar value to the global variables of the component.
Global Variable: Syntax

Declaring one or more global variables

GLOBAL
<Variables globales>
Details of syntax
GLOBALBeginning of declaration of global variables.
<Global variables>Global variables to declare.
GLOBAL // Toutes les déclarations qui suivent sont des variables globales
Indice is int
NomClient is string
Taux is real

LOCAL // Toutes les déclarations qui suivent sont des variables locales
I is int 
PrénomClient is string
Prix is currency
Local variable
Local variables can only be used in the events or processes in which they are declared. Outside of these events or processes, local variables are unknown. These variables cannot be shared by several events or processes.
By default, a variable is local when it is declared.
Local variable: Syntax

Declaring one or more local variables

[LOCAL]
<Variables locales>
Details of syntax
LOCALBeginning of declaration of local variables. The LOCAL keyword is optional.
<Local variables>Local variables to declare.

LOCAL // Toutes les déclarations qui suivent sont des variables locales
I is int
PrénomClient is string 
Prix is currency
// Toutes les déclarations qui suivent sont des variables locales
I is int
PrénomClient is string 
Prix is currency
Zombie local and global variables
A local or global variable can become obsolete. This allows you to in know that this element must not be used anymore (but that it is not deleted yet).
To declare a variable as being obsolete, all you have to do is use the <Zombie> extension attribute.
The syntax is as follows:
<Nom Variable> est un <type de la variable> <zombie [commentaire = "texte"]>
In this syntax, the optional comment keyword is used to specify the text that will be displayed in the compilation error associated with the obsolete variable.
Example:
PrénomClient is string <zombie commentaire = "Ne plus utiliser - utiliser la structure Client">
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/24/2024

Send a report | Local help