LMD ScriptPack Guide
PasScipt language supports a variety set of expressions to allow script program to assign variables, call procedures and functions, accessing objects properties (including indexed properties), perform logical and math operations and more.
PasScript supports Integer, floating-point and string literals, as well as nil, True, False, Unassigned and Null constants. Here are some examples:
x := 7;
x := -7;
x := 7.0;
x := +0.25E+10;
s := 'Some string';
Integers in hexadecimal form are also supported with the syntax similar to Delphi:
x := $A23BD7;
String literals also has syntax close to Delphi, including escaping the quote char and specifying non-printable characters using # symbol:
s := 'This is a string containing a single '' symbol';
s := 'This is a '#13#10'two line string';
The keyword nil is used to denote no-object value. It is equivalent to Nothing in VBScript and represented as a Variant with VType = varDispatch and VDispatch = nil;
The Unassigned is used to denote not yet assigned (or empty) variable. It is equivalent to VBScript Empty constant and represented as a Variant with VType = varEmpty.
The Null is used to denote database NULL value, which has the meaning of unknown/unspecified value; represented as a Variant with VType = varNull.
The following operators are supported by PasScript language:
> |
Greater than |
< |
Less than |
>= |
Greater or equal |
<= |
Less or equal |
<> |
Not equal |
= |
Equal |
in |
Value in set. Used with imported from Delphi set types; for example: if fsBold in Font.Style then See set constructors for more info. |
is |
Value is of type. Used with imported from Delphi class and record types to test whether the object or record instance is of specified type; for example: if obj is TButton then |
+ |
Addition. |
- |
Substraction |
* |
Multiplication |
/ |
Division |
div |
Integer division |
mod |
Integer modulus |
or |
Logical or. "Incomplite Boolean eval" logic is used. |
xor |
Logical/bitwise xor |
and |
Logical and. "Incomplite Boolean eval" logic is used. |
shl |
bitwise shift to left |
shr |
bitwise shift to right |
not |
Unary logical not |
@ |
Make event handler. Look here for more info. |
The and and or operators use incomplete Boolean evaluation logic, just like in Delphi. That is, the second operand is evaluated only when necessary. The following examples demonstrate the advantage of this evaluation strategy:
if (obj <> nil) and (obj.Width < 100) then
DoSomething;
if (obj = nil) or (obj.Width >= 100) then
DoSomething;
In both cases obj.Width will be evaluated only if obj is not equal to nil. In both cases no error is possible, because when the obj is nil, the second part of the expression is not evaluated.
PasScript uses Delphi like syntax to call global procedures/function as well as object methods/properties. Parameters for procedures/functions/methods are specified in round brackets; however if there no parameters expected, the brackets can be omit. Parameters for indexed properties are specified in square brackets. Here some examples:
P(5, 7);
x := F1(3);
x := F2; // Brackets omit.
x := F2();
h := MyFont.Height;
s := Application.ActiveForm.Caption;
s := Memo.Lines.Items[5]; // Indexed property
PasScript supports special syntax for working with set types imported from Delphi. Set constructors allows to specify set elements in square brackets to compose a set value. Empty set value is also supported. Here are some examples:
Font.Style := [fsBold, fsItalic];
Font.Style := []; // Empty set.
Recall that to test, whether an element included in the set value, script program can use in operator:
if fsBold in Font.Style then
ShowMessage('Font is bold');
Delphi like Include and Exclude intrinsic functions are also supported:
FontStyle := [];
if NeedBoldFont then
Include(FontStyle, fsBold);
Font.Style := FontStyle;
PasScript supports special syntax for creating a references to procedures written in script-code and assigning these references to events of objects. This can be done using @ symbol:
procedure Button1Click(Sender);
begin
ShowMessage('Hello from script');
end;
begin
Button1.OnClick := @Button1Click;
end;
The global code from the above example assigns a procedure written in script-code to the OnClick button's event. After assignment, clicking on the button will execute Button1Click procedure.