|Top Previous Next|
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:
Incomplite Boolean evaluation
The and and or operators use incomplite 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
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.
Calling object methods and accessing properties
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:
x := F1(3);
x := F2; // Brackets omit.
x := F2();
h := MyFont.Height;
s := Application.ActiveForm.Caption;
s := Memo.Lines.Items; // 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
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:
ShowMessage('Hello from script');
Button1.OnClick := @Button1Click;
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.