PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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 straightforward. The variable type is deduced according to the value that is assigned to the variable.
The value can be assigned:
Versions 20 and later
WEBDEV - Browser code This feature is available in browser code.
WEBDEV - Browser code Only the type inference by copy is available.
New in version 20
WEBDEV - Browser code This feature is available in browser code.
WEBDEV - Browser code Only the type inference by copy is available.
WEBDEV - Browser code This feature is available in browser code.
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.
Versions 19 and later
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.
New in version 19
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.
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
Versions 19 and later
// Multiple inference
let (x, y) = (1, "A")

// Multiple inference via a procedure returning multiple values
let (x, y) = MyProcedureWithMultipleReturns()
New in version 19
// Multiple inference
let (x, y) = (1, "A")

// Multiple inference via a procedure returning multiple values
let (x, y) = MyProcedureWithMultipleReturns()
// Multiple inference
let (x, y) = (1, "A")

// Multiple inference via a procedure returning multiple values
let (x, y) = MyProcedureWithMultipleReturns()
Note: 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 Param1 variable will have the same type as the value passed in 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 the 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
integer on 2 bytesint
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.
Versions 19 and later
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.
New in version 19
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.
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, ...
During an assignment by reference, the value of reference variable is not copied into 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
Minimum required version
  • Version 18
This page is also available for…
Comments
Click [Add] to post a comment