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
  • Type inference: assignment by copying
  • Syntaxes
  • Operating mode
  • The simple types supported by the assignment by copy
  • Type inference: assignment by reference
  • Syntaxes
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
The type inference is used to simplify the declaration of variables when the variable type can be automatically deduced by the compiler. The process is very simple. The variable type is deduced according to the value that is assigned to the variable.
The value can be assigned:
Type inference: assignment by copying

Syntaxes

1. Simple inference:
soit <Variable> = <Valeur>
where:
  • <Variable> corresponds to the name of variable to declare.
  • <Value> corresponds to the value assigned to the variable to declare.
2. Multiple inference:
soit (<Variable 1>, ..., <Variable N>) = (<Valeur 1>, ..., <Valeur N>)
where:
  • ... are the names of the variables to be declared.
  • ... correspond to the values assigned to each variable to be declared.

Operating mode

During the assignment by copy, if the variable type can be defined during the compilation, the variable is declared according to the type of value. A copy of value is assigned to the variable.
Examples:
let Montant = 1500.69 // type réel

let Ville = "Montpellier" // type chaîne
// Inférence multiple
let (x, y) = (1, "A")

// Inférence multiple via une procédure renvoyant des valeurs multiples
let (x, y) = MaProcédureARetourMultiple()
Note: The variable retains its type and does not change type during execution, even if another value of a different type is assigned to it.
If the variable type cannot be defined during the compilation, the type will be defined during the execution, dynamically (like when a procedure parameter has no type).
For example:
// Cas type inconnu au moment de la compilation
PROCEDURE MaProc(Param1)

let MaVar = Param1 

// Comme le paramètre Param1 n'est pas typé, 
// son type est inconnu au moment de la compilation
// La variable Param1 sera typée du type de la valeur passée en paramètre 
// au moment de l'appel de la procédure.
// La variable MaVar sera donc typée également 
// du type de la variable Param1 connu uniquement au moment de l'exécution.

The simple types supported by the assignment by copy

The simple types supported by the assignment by copy are as follows:
Type of valueType used
booleanboolean
1-byte unsigned integerint
2-byte unsigned integerint
4-byte unsigned integer4-byte unsigned integer
8-byte unsigned integer8-byte unsigned integer
1-byte integerint
2-byte integerint
intint
8-byte integer8-byte integer
currencycurrency
decimaldecimal
4-byte real4-byte real
realreal
charactercharacter
stringstring (Ansi or Unicode)
string of Nstring (Ansi or Unicode)
ANSI stringANSI string
Ansi string of NANSI string
Unicode stringUnicode string
Unicode string on NUnicode string
ASCIIZ string of NANSI string
Fixed string of NANSI string
Pascal string of NANSI string
bufferbuffer
datedate
timetime
datetimedatetime
durationduration
fontfont
procedureprocedure
Type inference: assignment by reference

Syntaxes

1. Simple inference:
soit <Variable> <- <Valeur>
where:
  • <Variable> corresponds to the name of variable to declare.
  • <Value> corresponds to the value assigned to the variable to declare.
2. Multiple inference:
soit (<Variable 1>, ..., <Variable N>) <- (<Valeur 1>, ..., <Valeur N>)
where:
  • ... are the names of the variables to be declared.
  • ... correspond to the values assigned to each variable to be declared.
The assignment by reference is available for the complex types only:
  • Object type: Class, Structure, .NET Class, advanced type, ...
  • Container type: Array, Associative array, Stack, Queue, List, ...
When assigning by reference, the value of the reference variable is not copied to the new variable but the new variable points to the reference variable.
In this case, if the reference variable is modified, the new variable is also modified.
Example:
clMonClient is cClient // classe cClient, objet clMonClient
let clClient <- clMonClient // type classe, clClient pointe sur l'objet clMonClient

tabPrix is array of 5 currencies
tabPrix[1] = 500.00
tabPrix[2] = 250

let tPrix <- tabPrix // type tableau, tPrix pointe sur le tableau tabPrix
AndroidAndroid Widget Type inference by reference is not supported in Associative arrays.
Minimum version required
  • Version 18
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/19/2024

Send a report | Local help