ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / Declaring variables
  • Overview
  • Type inference: assignment by copy
  • Syntaxes
  • Operating mode
  • The simple types supported by the assignment by copy
  • Type inference: assignment by reference
  • Syntaxes
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 type inference is used to simplify the declaration of variables when the variable type can be automatically deduced by the compiler. The principle is very simple. The variable type is deduced according to the value that is assigned to the variable.
The value can be assigned:
WEBDEV - Browser code Only the type inference by copy is available.
Type inference: assignment by copy

Syntaxes

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

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 Amount = 1500.69 // real type
 
let City = "Montpellier" // string type
// Multiple inference
let (x, y) = (1, "A")
 
// Multiple inference via a procedure returning multiple values
let (x, y) = MyProcedureWithMultipleReturns()
Remark: The variable keeps its type ; its type does not change during the 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:
// Case of unknown type during the compilation
PROCEDURE MyProc(Param1)
 
let MyVar = Param1
 
// As the Param1 parameter has no specific type,
// its type is unknown during the compilation
// The type of the Param1 variable will be based on the value passed as parameter
// during the call to the procedure.
// The MyVar variable will also have the same type
// as the type of the Param1 variable known during the execution.

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
unsigned integer on 1 byteint
unsigned integer on 2 bytesint
unsigned integer on 4 bytesunsigned integer on 4 bytes
unsigned integer on 8 bytesunsigned integer on 8 bytes
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 on Nstring (Ansi or Unicode)
Ansi stringAnsi string
Ansi string on NAnsi string
Unicode stringUnicode string
Unicode string on NUnicode string
ASCIIZ string on NAnsi string
Fixed string on NAnsi string
Pascal string on NAnsi string
bufferbuffer
datedate
timetime
datetimedatetime
durationduration
fontfont
procedureprocedure
Type inference: assignment by reference

Syntaxes

1. Simple inference:
let <Variable> <- <Value>
where:
  • <Variable> corresponds to the name of variable to declare.
  • <Value> corresponds to the value assigned to the variable to declare.
2. Multiple inference:
let (<Variable 1>, ..., <Variable N>) <- (<Value 1>, ..., <Value N>)
where:
  • <Variable 1> ... <Variable N> correspond to the names of variables to declare.
  • <Value 1> ... <Value N> correspond to the values assigned to each variable to declare.
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:
clMyClient is cClient // cClient class, clMyClient object
let clClient <- clMyClient // class type, clClient points to clMyClient object
 
arrPrice is array of 5 currencies
arrPrice[1] = 500.00
arrPrice[2] = 250
 
let tPrice <- arrPrice // array type, tPrice points to the arrPrice array
AndroidAndroid Widget Java 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: 05/26/2022

Send a report | Local help