The Explorer GUI script engine executes scripts
written using a 'Pascal-like' syntax. The Explorer
GUI Pascal syntax supports:
The following language constructs are supported:
-
begin .. end -
procedureandfunctiondeclarations -
if .. then .. else -
for .. to .. do -
while .. do -
repeat .. until -
try .. exceptandtry .. finallyblocks -
casestatements -
with,asandisstatements - array constructors (for example,
x := [1, 2, 3];) - operators such as:
-
^ -
* -
/ -
, -
+ -
- -
or -
<> -
>= -
<= -
= -
> -
< -
div -
mod -
xor -
shl -
shr
The script structure is made of two major blocks: a)
procedure and function declarations
and b) the main block. The main block is required; procedure/function
declarations are optional. There is no need for the main block to be
inside begin..end keywords — it can be a single
statement.
Examples:
//SCRIPT 1:
procedure DoSomething; begin
end; begin end;
CallSomething;
CallSomethingElse;
//SCRIPT 2:
begin
CallSomethingElse;
end;
//SCRIPT 3:
function MyFunction; begin
result:='Ok!';
end;
//SCRIPT 4:
CallSomethingElse;
Like Pascal, statements should be terminated by the ;
character. begin..end blocks are allowed to group
statements.
Identifiers
Identifier names in scripts (variable names, function and procedure
names, etc.) follow the common Pascal rules. They must begin with a
letter (a..z or A..Z) or
_, and can be followed by alphanumeric characters or
the _ character. Identifiers cannot contain any other
characters or spaces.
Valid identifiers:
-
VarName -
_Some V1A2 -
Some
Invalid identifiers:
-
2Var -
My Name -
Some-more -
This,is,not,valid
Assign statements (assign a value or expression result to a variable or
object property) use the := operator.
Examples:
MyVar:=2;
Caption:='This ' + 'is ok.';
Character strings
Strings (sequences of characters) are declared using the single quote
(') character. Double quotes (") are
not used. You can use #nn to declare a character inside
a string. There is no need to use the + operator to add
a character to a string.
#nn for
character codes (for example, #13#10 for CR+LF).Examples:
A:='This is a text';
Str:='Text '+'concat';
B:='String with CR and LF char at the end'#13#10;
C:='String with '#33#34' characters in the middle';
Comments can be inserted inside a script. You can use
//, (* *) or { }
blocks. Using // ends the comment at the end of the
line.
Examples:
//This is a comment before ShowMessage
ShowMessage('Ok');
(* This is another comment *) ShowMessage('More ok!');
{
And this is a comment with two lines }
ShowMessage('End of okays');
Variables
There is no need to declare variable types. Declare variables using the
var directive followed by the name.
Examples:
//SCRIPT 1:
procedure Msg;
var
S;
begin
S:='Hello world!'; ShowMessage(S);
end;
//SCRIPT 2:
var A;
begin
A:=0;
A:=A+1;
end;
//SCRIPT 3:
var S;
S:='Hello World!';
ShowMessage(S);
Strings, arrays and array properties can be indexed using
[ and ]. For example, if
Str is a string variable, the expression
Str[3] returns the third character; Str[I +
1] returns the character immediately after the one indexed by
I.
Examples:
MyChar:=MyStr[2];
MyStr[1]:='A';
MyArray[1,2]:=1530;
Lines.Strings[2]:='Some text';
Arrays
Scripts support array constructors and variant arrays. To construct an
array, use [ and ]. You can construct
multi-index arrays by nesting array constructors. Access arrays using
indexes; for multi-index arrays, separate indexes with
,. Arrays are zero-based indexed.
Examples:
NewArray := [ 2,4,6,8 ];
Num := NewArray[1]; // Num receives "4"
MultiArray := [ ['green','red','blue'] , ['apple','orange','lemon'] ];
Str := MultiArray[0,2]; // Str receives 'blue'
MultiArray[1,1] := 'new orange';
There are two forms of if statements: if ...
then and if ... then ... else. If the
expression is true, the statement or block after then
is executed. If there is an else part and the
expression is false, the statement or block after else
is executed.
Examples:
if J <> 0 then Result := I/J;
if J = 0 then Exit else Result := I/J;
if J <> 0 then
begin
Result := I/J;
Count := Count + 1;
end
else
Done := True;
While statements
A while statement repeats a statement or block while a
control expression evaluates to true. The condition is evaluated before
each iteration; if false initially, the body is never executed.
Examples:
while Data[I] <> X do I := I + 1;
while I > 0 do
begin
if Odd(I) then Z := Z * X;
I := I div 2;
X := Sqr(X);
end;
while not Eof(InputFile) do begin
Readln(InputFile, Line);
Process(Line);
end;
The repeat statement has the form: repeat
statement1; ...; statementn; until expression. The sequence
is executed repeatedly and the expression is evaluated
after each iteration. The sequence is always executed at least once
because the expression is checked after the first iteration.
Examples:
repeat
K := I mod J;
I := J;
J := K;
until J = 0;
repeat
Write('Enter a value (0..9): '); Readln(I);
until (I >= 0) and (I <= 9);
For statements
for statements use this syntax: for counter :=
initialValue to finalValue do statement. The counter is set
to initialValue, the statement or block is executed,
and the counter increments until it reaches
finalValue.
Examples:
for c := 1 to 10 do
a := a + c;
for i := a to b do begin
j := i^2;
sum := sum + j;
end;
case statements use the form case
selectorExpression of ... end. If the selector expression
matches one of the case expressions, the corresponding statement or
block executes; otherwise the optional else part
executes. Case expressions are not limited to ordinal values — you can
use expressions of any type.
Example:
case lowercase(Fruit) of
'lime': ShowMessage('green');
'orange': ShowMessage('orange');
'apple': ShowMessage('red');
else
ShowMessage('black');
end;
Function and procedure declaration
Function and procedure declarations are similar to Pascal, except you
do not specify variable types. To return function values, use the
implicitly declared result variable. Parameters by
reference can be used with the var keyword; you still
do not specify variable types.
Examples:
procedure HelloWord;
begin
ShowMessage('Hello world!');
end;
procedure UpcaseMessage(Msg);
begin
ShowMessage(Uppercase(Msg));
end;
function TodayAsString;
begin
result := DateToStr(Date);
end;
function Max(A,B);
begin
if A > B then
result := A
else
result := B;
end;
procedure SwapValues(var A, B);
var
Temp;
begin
Temp := A;
A := B;
B := Temp;
end;