Pascal Script – Quick Guide for JavaScript Developers
This guide covers the core syntax and principles of base Pascal Script as used in the Hyper Scripting System.This guide transitions you from the dynamic nature of JavaScript to the structured, strongly-typed environment of Pascal Script.
- The language is NOT case sensitive at all.
- Statements end with a semicolon (;). Line breaks do not affect code execution.
- Blocks of code use begin ... end instead of { ... }.
- Programs, procedures, and functions must declare all variables before use.
- Assignment to variables uses the := symbol.
- Single-line Comment: // This is a comment
- Multi-line Comment: { This is a block comment }
Index
- Supported Data Types
- Symbols and Their Meaning
- Operators
- Variable Declaration (var) and Constants (const)
- IF Conditions
- Code Blocks: Begin...End vs. Single Line
- Iteration (Loops)
- Case
- Array
- TRY
- Procedures vs Functions
- Parameter Passing
- String Utilities
- Date/Time Basics
- Type Conversion
- Records
Supported Data Types
Unlike JavaScript's let or var, Pascal requires explicit type definitions. Below are the native types available in the script engine:| Type | Description | Min | Max |
|---|---|---|---|
| Integer | 32-bit signed integer. | -2147483648 | 2147483647 |
| Int64 / LongInt | 64-bit signed integer. | -9223372036854775808 | 9223372036854775807 |
| Word | 16-bit unsigned integer. | 0 | 65535 |
| Cardinal / LongWord | 32-bit unsigned integer. | 0 | 4294967295 |
| Double | Double-precision floating point, up to 15 decimals. | 2.23e-308 | 1.79e+308 |
| String | Ansi or Unicode string. | ||
| Char | Single Unicode character (16-bit). | ||
| Boolean | TRUE/FALSE flag. | ||
| Variant | Generic type, can store any value or object. |
Symbols and Their Meaning
Punctuation in Pascal follows strict rules that differ from JavaScript's C-style syntax.| Symbol | Description |
|---|---|
| := | Assignment: Sets a value to a variable (JS uses =). |
| = | Equality: Comparison operator used in conditions (JS uses ==). |
| <> | Inequality: Not equal to (JS uses !=). |
| < , > , <= , >= | Comparison operators: less, greater, less or equal, greater or equal. |
| ' ' | Single Quotes: String literals MUST use single quotes. |
Operators
Logical and arithmetic operations often use keywords instead of symbols.| Operator | Description |
|---|---|
| + | Addition for numbers or Concatenation for strings. |
| - , * , / | Subtraction, multiplication, division (/ returns a floating-point result). |
| DIV | Integer division (returns the whole number without remainder). |
| MOD | Remainder after integer division (JS: %). |
| NOT | Logical NOT (JS: !). |
| AND / OR | Logical AND / OR (JS: && and ||). |
| XOR | Logical exclusive OR (True only when operands differ). |
| SHL / SHR | Bitwise shift left / right. |
Variable Declaration (var) and Constants (const)
In Pascal Script, variables are declared before use in a var block, with explicit types. Constants are declared in a const block and cannot be changed at runtime.Typical order in a script unit is:
const -> var -> begin ... end;
const
MAX_RETRIES = 3;
APP_NAME = 'Pascal Demo';
var
counter: Integer;
userName: String;
isReady: Boolean;
begin
counter := 0;
userName := 'Dana';
isReady := True;
ShowMessage(APP_NAME + ' / retries: ' + IntToStr(MAX_RETRIES));
end;
// Multiple variables of the same type in one line
var
x, y, z: Integer;
begin
x := 10;
y := 20;
z := x + y;
end;
IF Conditions
Use if ... then ... else for conditional execution. Use parentheses for clarity in complex expressions.Important: do not place a semicolon (;) right before else.
var
age: Integer;
isMember: Boolean;
begin
age := 21;
isMember := True;
if (age >= 18) and (isMember = True) then
ShowMessage('Access granted')
else
ShowMessage('Access denied');
end;
// Else-if style (nested if in else branch)
if score >= 90 then
grade := 'A'
else if score >= 80 then
grade := 'B'
else
grade := 'C';
Code Blocks: Begin...End vs. Single Line
In JavaScript, curly braces { } group statements. In Pascal, we use begin and end.- Single Line: If an IF or Loop contains only one statement, begin/end is optional.
- Multi-line Block: Multiple statements MUST be wrapped in a begin...end; block.
- The Else Rule: You MUST NOT put a semicolon before an else keyword.
// Single line example
IF X > 10 Then
DoSomething;
// Block example
if (X <= 10) and (Y <> 0) then
Begin
X:= X + 1;
Y:= 0;
End;
Iteration (Loops)
All loop control variables (like i) must be declared in the var block before the loop begins.For
Strictly used for counting through a range.var
i: Integer;
begin
for i := 1 to 5 do
begin
ShowMessage('Iteration: ' + IntToStr(i));
end;
for i := 5 downto 1 do
begin
ShowMessage('Countdown: ' + IntToStr(i));
end;
end;
While
Repeats as long as the condition remains True.while (CurrentValue <= MaxLimit) do
begin
CurrentValue := CurrentValue + Step;
end;
Repeat...Until
Similar to do...while in JS; it always executes at least once and stops when the condition becomes True.repeat
ExecuteTask;
until (IsFinished = True);
Case
Case is the Pascal equivalent of JavaScript switch. It is used for clean multi-branch selection.var
dayNumber: Integer;
dayName: String;
begin
dayNumber := 3;
case dayNumber of
1: dayName := 'Sunday';
2: dayName := 'Monday';
3: dayName := 'Tuesday';
4: dayName := 'Wednesday';
5: dayName := 'Thursday';
6: dayName := 'Friday';
7: dayName := 'Saturday';
else
dayName := 'Unknown';
end;
end;
String-based case is also supported:
var
commandText: String;
begin
commandText := 'start';
case LowerCase(commandText) of
'start': ShowMessage('Starting...');
'stop': ShowMessage('Stopping...');
'pause': ShowMessage('Paused.');
else
ShowMessage('Unknown command: ' + commandText);
end;
end;
Array
Arrays store multiple values of the same type in indexed positions.var
scores: array[0..4] of Integer;
i: Integer;
begin
scores[0] := 10;
scores[1] := 20;
scores[2] := 30;
scores[3] := 40;
scores[4] := 50;
for i := 0 to 4 do
ShowMessage('Score #' + IntToStr(i) + ': ' + IntToStr(scores[i]));
end;
TRY
Use Try...Except to catch and handle runtime errors.var
x, y, z: Integer;
begin
x := 10;
y := 0;
try
z := x div y;
ShowMessage('Result: ' + IntToStr(z));
except
ShowMessage('An error occurred: division by zero.');
end;
end;
Use Try...Finally when cleanup code must run whether an error happens or not.
var
started: Boolean;
begin
started := False;
try
started := True;
ShowMessage('Starting task...');
ExecuteTask;
finally
if started then
ShowMessage('Cleanup completed.');
end;
end;
Procedures vs Functions
Procedure performs actions. Function returns a value.procedure LogMessage(msg: String);
begin
ShowMessage(msg);
end;
function AddNumbers(a, b: Integer): Integer;
begin
Result := a + b;
end;
var
sum: Integer;
begin
LogMessage('Calculating...');
sum := AddNumbers(7, 5);
ShowMessage('Sum = ' + IntToStr(sum));
end;
You can also create nested (local) subroutines inside another procedure/function.
Declare local helpers before the outer begin.
function BuildWelcomeMessage(userName: String): String;
function NormalizeName(const rawName: String): String;
begin
NormalizeName := Trim(rawName);
end;
begin
Result := 'Hello, ' + NormalizeName(userName);
end;
begin
ShowMessage(BuildWelcomeMessage(' Yaniv '));
end;
Parameter Passing
Regular parameters are passed by value. var parameters are passed by reference.procedure IncreaseByValue(x: Integer);
begin
x := x + 1;
end;
procedure IncreaseByRef(var x: Integer);
begin
x := x + 1;
end;
var
n: Integer;
begin
n := 10;
IncreaseByValue(n);
ShowMessage('After value call: ' + IntToStr(n)); // 10
IncreaseByRef(n);
ShowMessage('After var call: ' + IntToStr(n)); // 11
end;
String Utilities
Common string helpers are straightforward and strongly typed.var
s: String;
begin
s := ' Pascal Script ';
ShowMessage('Length: ' + IntToStr(Length(s)));
ShowMessage('Trim: [' + Trim(s) + ']');
ShowMessage('Upper: ' + UpperCase(s));
ShowMessage('Lower: ' + LowerCase(s));
ShowMessage('Pos of Script: ' + IntToStr(Pos('Script', s)));
ShowMessage('Copy 1..6: ' + Copy(Trim(s), 1, 6));
end;
Date/Time Basics
Date/time values are typed and easy to format.var
nowValue: TDateTime;
begin
nowValue := Now;
ShowMessage('Date: ' + DateToStr(Date));
ShowMessage('Time: ' + TimeToStr(Time));
ShowMessage('Now: ' + DateTimeToStr(nowValue));
ShowMessage('Custom: ' + FormatDateTime('yyyy-mm-dd hh:nn:ss', nowValue));
end;
Type Conversion
Conversions are explicit. Use Try variants when user input may be invalid.var
s: String;
n: Integer;
f: Double;
begin
s := '42';
n := StrToInt(s);
f := StrToFloat('3.14');
ShowMessage('IntToStr: ' + IntToStr(n));
ShowMessage('FloatToStr: ' + FloatToStr(f));
if TryStrToInt('abc', n) then
ShowMessage('Converted: ' + IntToStr(n))
else
ShowMessage('Invalid integer input.');
end;
Records
Record is a typed data structure similar to a simple object shape in JavaScript.type
TUser = record
Name: String;
Age: Integer;
Active: Boolean;
end;
var
user: TUser;
begin
user.Name := 'Dana';
user.Age := 28;
user.Active := True;
ShowMessage('User: ' + user.Name + ', age ' + IntToStr(user.Age));
end;