Variables
A Variable is a placeholder to store a value, and is declared as a certain data type indicating the type of data the Variable can store. A Variable can be one of many different data types, such as String, Integer or Boolean to name just a few. Please refer to Data Types for more information.
Declaring A Variable
Before a Variable can be used in a script or in a Map, it must be declared - which means that it is named and given a data type.
<var> is a keyword - indicating you are declaring a Variable.
<VariableName> is the desired name of the variable and can be what ever the user desires - however, the first character should always be a alphabetic character from A-Z. Variable names are not case sensitive in a script. If you declare as MyVariable, you can reference it is myvariable or any combination of upper and lower case letters.
<DataType> is one of the supported data types.
The syntax for declaring variables is -
var
<VariableName> : <DataType>;
The declaration can be on the same line as the keyword.
var
ColourType :
string
;
If declaring multiple Variables you only need this once at the start of the list of Variables, as below.
var
ColourType :
string
;
ColourCode :
integer
;
ColourTint :
string
;
A series of Variables of differing data types do not need t be declared on separate lines - they can be declared on one line if that makes it easier to read. The following illustrates the declaration of three (3) variables - ThisTotal of Double data type, ThatCount of Integer data type, and WhatTemp which is declared as a String data type.
var
ThisTotal :
Double
; ThatCount :
Integer
; WhatTemp :
String
;
Variables of the same data type can be strung together on the same line with a comma separator, as follows.
var
ColourType, ColourTint :
string
;
ColourCode :
integer
;
A user can also declare local Variables making them available for use within the script. A Variable is declared before the begin...end block of the script skeleton.
procedure
ScriptEvent (
var
Value : variant);
var
MyVariable :
Integer
;
MyVariable2 :
String
;
MyDay : TDateTime;
begin
.....
.....
end
;
A Variable is called a Parameter when it is an input to a Function.
Persistent Or Non-persistent
Variables can also be either Persistent or Non-persistent.
All Variables declared by the user are Non-persistent, as they do not retain their value between executions of the script - they always start as null each time the script executes. For example, in a script assigned to the OnMap event of a field, a variable will start as null each time the script executes and it will execute once for each record being processed.
Persistent Variables retain their value between each execution of the script.
Local Or Global
A Variable has a scope which indicates the availability of the Variable from within the script, and can be described as either Local or Global.
A Local Variable is only available within the script that it is declared in. Any Variables declared by a user are considered to be Local Variables and are only available within the script they are declared within.
Whereas a Global Variable is available within any script within the Map. A user cannot declare Global variables.
As well as Local Variables declared by the user as above, there are also special Variables that are available within the script engine.
Special Variable | Predeclared Names | Data Type | Scope / Persistence |
---|---|---|---|
Global Variable | Global1 to Global10 | Variant | Across Events in one execution of a Map. |
Global Dataset | Data1 to Data44 | TFloClientDataSet | Across Events in one execution of a Map. |
Super Global | Globals['<anyname>'] | Variant | The lifetime of that Statelake session in memory, or until RemoveGlobal or ClearAllGlobals. |
Local Global | Locals['<anyname>'] | Variant | Across Action Steps in one execution of an Action, or until RemoveLocal or ClearAllLocals. |