The reduced modifier is used to avoid a memory leak. The reduced assignment[Reduced] ['@'] Expr1 ['^'] := ['@'] Expr2 ['^'] ';'
meansreduced A := E;
if A is array and E is element of A. Otherwise it means:Dim temp := E; E := nil; delete A; A := temp;
delete A; A := E;
The ^ at the left part of the assignment statement should be used only when Expr1 is alias and @ is presented at the right part of the statement. (Because Expr1 ^ = Expr2 produces the same assignment as Expr1 = Expr2 in all another cases). When @ is presented at the right part, the use of ^ in the left part allows you to assign alias of Expr2 to terminal of Expr1. For example:
It producesvar A[10], B, C, P; B := 300; C := 500; P := @ A[5]; P^ := @ B; writeln(P); writeln(A[5]); P := @ C; writeln(A[5]); writeln(P);
The ^ at the left part of the assignment statement should be used only when Expr2 is an alias. In this case, the use of ^ allows you to assign Expr1 as alias of terminal of Expr2. For example300 300 300 500
This example illustrates how the search of most general unifier works (mechanical theorem proving). T1 and T2 represent terms, P1 and P2 are parameters of T1 and T2 accordingly. The last statementvar P1 = "X"; var P2 = "Y"; var T1 = ["R", ["F", @ P1]]; var T2 = ["R", @ P2]; var Q1 = @ T1[1]; var Q2 = @ T2[1]; Q2^ := @ Q1^;
changes parameters, not source terms.Q2^ := @ Q1^;
- Dim Statements
/ul>
Executing the break statement exits from the current loop or statement, and begins script executionGrammar
BreakStmt -> break [Label] ';'Arguments
LabelOptional. Specifies the label of the statement you are breaking from.Example
L: for I:=1 to 10 do for J:=1 to 5 do if J = 3 then Break L else writeln(I, ' ', J);See Also
The case statement provides a readable alternative to complex nested if conditionals.Grammar
CaseStmt -> case SelectorExpression of CaseSelector/';'... [else Statement] [';'] end ';' CaseSelector -> CaseLabel/','... ':' Statement CaseLabel -> ConstExpr ['..' ConstExpr]Arguments
SelectorExpressionAny numeric or string expression.CaseSelectorOne of the following:
- a numeral constant, or other expression that the compiler can evaluate without executing your program.
- a subrange having the form First..Last, where First and Last both satisfy the criterion above and First is less than or equal to Last
- a list having the form item1, ..., itemn, where each item satisfies one of the criteria above
Example 1
case MyColor of Red: X := 1; Green: X := 2; Blue: X := 3; Yellow, Orange, Black: X := 0; end;Example 2
case Selection of Done: Form1.Close; Compute: CalculateTotal(UnitCost, Quantity); else Beep; end;See Also
- If Statements
/ul>
Declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class.Grammar
ClassStmt -> class Ident [ '(' Ancestor ')' ] MemberStatement /... end ';' MemberStatement -> ConstructorStmt | VarStmt | FunctionStmt | ProcedureStmt | PropertyStatement |Arguments
IdentName of the class.AncestorOptional. Name of the ancestor class.MemberStatementOne or more statements that define the variables, properties, and methods of the class.Example 1
class TPoint X, Y: Double; constructor Create(X, Y); begin Self.X := X; Self.Y := Y; end; end; class TCircle(TPoint) R: Double; constructor Create(X, Y, R); begin inherited Create(X, Y); Self.R := R; end; end;All constructors must have name Create.Example 2
var Point = TPoint.Create(3, 5), Circle = TCircle.Create(3, 5, 7);Classes can have static (shared) members. The definition of a static member must begin with the reserved word class. For example,Example 3
class TFoo(TObject) class var X: String; class function F(): Integer; begin result := 23; end; class procedure P(); begin print X; end; end;Here X, F and P are static members of class TFoo. Use Type statement instead of the Class statement to provide native Object Pascal syntax for your scripts.See Also
A compound statement is a sequence of other (simple or structured) statements to be executed in the order in which they are written.Grammar
The compound statement is bracketed by the reserved words begin and end, and its constituent statements are separated by semicolons.CompoundStmt -> begin Statement /';'... endExample
begin Z := X; X := Y; Y := Z; end;
Creates new constants.Grammar
ConstStmt -> [const] [':' TypeIdent] = Value /,... ';'Arguments
ValueValue of constant.TypeIdentType of constantExample
const PI = 3.14;
A constructor is a special method that creates and initializes instance objects.Grammar
The declaration of a constructor looks like a procedure declaration, but it begins with the word constructor.ProcedureStmt -> constructor Ident ['(' FormalParm/','... ')'] ';' begin Statement /';'... end ';' FormalParm -> [var] ParameterExample
class TPoint var X, Y; constructor Create(X, Y); begin Self.X := X; Self.Y := Y; end; end; var P = TPoint.Create;See Also
The continue statement stops the current iteration of a loop, and starts a new iteration.Grammar
ContuinueStmt -> continue [Label] ';'Arguments
LabelOptional. Specifies the statement to which continue applies. A local variable (declared in the block containing the for statement) without any qualifiersExample
L: for I:=1 to 10 do for J:=1 to 5 do if J = 3 then Continue L else writeln(I, ' ', J);See Also
Destroys variable or its terminalGrammar
DeleteStmt -> Delete Expression [^]
Creates enumeration type.Grammar
Use Type statement instead of the Enum statement to provide native Object Pascal syntax for your scripts.EnumStmt -> enum '(' Ident {'=' Number} /','... ')'';'Example
enum E (a, b = 10, c); var x: E; print x.a; print x.b; print x.c;See Also
- Type Statements
/ul>
Exits from the current procedure.Grammar
ExitStmt -> exit ';'See Also
A for statement, unlike a repeat or while statement, requires you to specify explicitly the number of iterations you want the loop to go through.Grammar
ForStmt -> for Counter ':=' InitialValue (to|downto) FinalValue do StatementArguments
CounterNumeric variable used as a loop counter. The variable can't be an array element or an element of a user-defined type.InitialValueInitial value of Counter.FinalValueFinal value of CounterStatementThe for statement assigns the value of InitialValue to Counter, then executes statement repeatedly, incrementing or decrementing Counter after each iteration. (The for...to syntax increments Counter, while the for...downto syntax decrements it.) When Counter returns the same value as FinalValue, statement is executed once more and the for statement terminates. In other words, statement is executed once for every value in the range from InitialValue to FinalValue. If InitialValue is equal to FinalValue, statement is executed exactly once. If InitialValue is greater than FinalValue in a for...to statement, or less than FinalValue in a for...downto statement, then statement is never executed.A simple or structured statement that does not change the value of Counter.Example 1
for I := 2 to 63 do if Data[I] > Max then Max := Data[I];Example 2
for I := ListBox1.Items.Count - 1 downto 0 do ListBox1.Items[I] := UpperCase(ListBox1.Items[I]);See Also
Declares the name, arguments, and code that form the body of a function.Grammar
FunctionStmt -> [class] function Ident ['(' FormalParam/','... ')'] ';' [[call_convention] external DllName [name FuncName]';'] begin Statement /';'... end ';' FormalParam -> [var] ParameterArguments
IdentThe name of the function.ParameterRepresents formal parameter of function. The var keyword indicates that the argument is passed by reference.StatementAny simple or structured statement.ClassOptional. The class keyword specifies a static (shared) method of a class. Can be used only inside of a class body.call_conventionSpecial variable Result holds the function's return value. Functions and procedures can be nested.One of: pascal, cdecl, stdcall, register, safecall.Example 1
function Fact(N: Integer): Integer; begin if N = 1 then result := 1 else result := N * Fact(N - 1); end; end;You can use the function statement inside of a class body. In such case the statement declares a method of the class.Example 2
class TMyClass(TObject) Z: String = 'abc'; function DoubleZ: String; begin result := Z + Z; end; class function Hello: String; begin result := 'Hello ' + ClassName; end; end;Example 3
const DllName = 'TestDll.dll'; function Min(X, Y: Integer): Integer; stdcall; external DllName name Min; function Max(X, Y: Integer): Integer; stdcall; external DllName;See Also
Transfers program execution to a labeled statement.Grammar
GotoStmt -> goto Label ';'Arguments
LabelA unique identifier used when referring to the labeled statement.Example
for I:=1 to 10 do for J:=1 to 5 do if I + J = Random(15) then goto L; L: print I, J;See Also
- Labeled Statements
/ul>
Initiates abnormal termination of a program.Grammar
HaltStmt -> halt [ ExitCode] ';'Arguments
ExitCodeOptional. An expression that specifies an exit code for the program.
Conditionally executes a group of statements, depending on the value of an expression.Grammar
IFStmt -> if Condition then Statement1 [else Statement2] ';'Arguments
ConditionA Boolean expression. If condition is null or undefined, condition is treated as false.Statement1The statement to be executed if condition is true.Statement2Optional. The statement to be executed if condition is false.Example 1
if y = 6 then z := 17;Example 2
if x > 0 then s := 1 else s := -1;See Also
- Case Statements
/ul>
Creates new labels.Grammar
LabelStmt -> label Ident, /... ';'Arguments
IdentIdentifier of label.Example
var I, J: Integer; label Outer; begin Outer: for I:=1 to 3 do for J:=1 to 4 do begin if (I = 2) and (J = 3) then Continue Outer; print I, J; end; end;See Also
- Labeled Statements
/ul>
Provides an identifier for a statement.Grammar
LabeledStmt -> L ':' Statement ';'Arguments
LA unique identifier used when referring to the labeled statement.StatementAny statement.Example
L: for I:=1 to 10 do for J:=1 to 5 do if J = 3 then Break L else writeln(I, ' ', J);See Also
Programs are organized using namespaces. You can consider the namespace as a class which contains only static (shared) members.Grammar
NamespaceStmt -> namespace StatementList end ';'Arguments
StatementListOne or more statementsExample
namespace Shapes var ShapeCount, ShapeList[100]; procedure RegisterShape(S); begin ShapeCount := ShapeCount + 1; ShapeList[ShapeCount] := S; end; class TPoint var X, Y; constructor Create(X, Y); begin Self.X := X; Self.Y := Y; RegisterShape(Self); end; end; class TSquare var X1, Y1, X2, Y2; constructor Create(X1, Y1, X2, Y2); begin Self.X1 := X1; Self.Y1 := Y1; Self.X2 := X2; Self.Y2 := Y2; RegisterShape(Self); end; end; end; var P = Shapes.TPoint.Create(3, 5);See Also
- Program Statements
/ul>
Prints value of an expression.Grammar
PrintStmt -> print Expression/','... ';'Example
print 4 * 100 div 7;
Declares the name, arguments, and code that form the body of a procedure.Grammar
ProcedureStmt -> [class] procedure Ident ['(' FormalParam/','... ')'] ';' [[call_convention] external DllName [name ProcName]';'] begin Statement /';'... end ';' FormalParam -> [var] ParameterArguments
IdentThe name of the procedure.ParameterRepresents formal parameter of function. The var keyword indicates that the argument is passed by reference.StatementAny simple or structured statement.ClassOptional. The class keyword specifies a static (shared) method of a class. Can be used only inside of a class body.call_conventionFunctions and procedures can be nested.One of: pascal, cdecl, stdcall, register, safecall.Example 1
procedure Hanoi(N, X, Y, Z); begin if N > 0 then begin Hanoi(N - 1, X, Z, Y); print 'Transfer a ring from ' + X + ' to ' + Y; Hanoi(N - 1, Z, Y, X); end; end;You can use the procedure statement inside of a class body. In such case the statement declares a method of the class.Example 2
class TMyClass(TObject) var Z = 'abc'; procedure PrintZ; begin print Z; end; class procedure PrintHello; begin print 'Hello '; end; end;Example 3
procedure MyProc(X, Y: Integer); external 'MyDllName.dll'; MyProc(2, 50);See Also
- Function Statements
/ul>
Creates new namespace and passes parameters to the script.Grammar
program Ident ['(' Param, /... ')'] ';'Arguments
IdentName of the namespace.ParamParameters are passed to the script by reference.Optional. Name of parameter.Example
program P(A, B); begin print A; B := 100; end.See Also
- Namespace Statements
/ul>
A property, like a field, defines an attribute of an object. But while a field is merely a storage location whose contents can be examined and changed, a property associates specific actions with reading or modifying its data. Properties provide control over access to an object’s attributes, and they allow attributes to be computed.Grammar
PropertyStmt -> property Ident [ParamList] ( [read IdentRead] | [write IdentWrite] ) Specifiers ';' [default]';' ParamList -> '[' Param/','... ']'Arguments
IdentName of the propertyParamOptional. Parameter of indexed propertyIdentRead, IdentWriteClass members which represent read and write specifiers accordinglyDefaultOptional. Specifies an indexed property which is array property. A class can have only one default property.Example
class TMyClass(TObject) var fZ = [10, 20, 30, 40, 50]; function GetElement(I); begin result := fZ[I]; end; procedure SetElement(I, Value); begin fZ[I] := Value; end; property Z[I] read GetElement write SetElement; default; end; var X = TMyClass.Create; X[1] := 50;See Also
- Class Statements
/ul>
Generates an error condition that can be handled by a try...exceptÅfinally statement.Grammar
RaiseStmt -> raise [Ident] ';'Arguments
IdentOptional. If Ident is ommited the statement re-raises the current exception, otherwise Ident represents an exception object.Example
try try raise 100; except on E do begin print 'except'; print E; end; end; finally print 'finally'; end;See Also
Creates a record type.Grammar
RecordStmt -> record Ident [ '(' Ancestor ')' ] MemberStatement /... end ';' MemberStatement -> VarStmt | FunctionStmt | ProcedureStmt | PropertyStatement |Arguments
IdentName of the record typeAncestorOptional. Name of the ancestor record type.MemberStatementOne or more statements that define the variables, properties, and methods of the record.Example 1
record X: Integer = Random(100); Y: Integer = Random(100); end; record TRandomCircle (TRandomPoint) R: Integer = Random(100); end; var C: TRandomCircle; print C;Method Initialize provides another way to initialize the record fields.Example 2
record X, Y: Integer; procedure Initialize; begin X := Random(100); Y := Random(100); end; end; record TRandomCircle (TRandomPoint) R: Integer; procedure Initialize; begin R := Random(100); end; end; var C: TRandomCircle; // calls Initialize here print C;Use Type statement instead of the Record statement to provide native Object Pascal syntax for your scripts.See Also
Grammar
RepeatStmt -> repeat Statement until Condition ';'Arguments
ConditionA Boolean expression. If condition is undefined, condition is treated as false.StatementThe repeat statement executes its sequence of constituent statements continually, testing Condition after each iteration. Whe Condition returns True, the repeat statement terminates. The sequence is always executed at least once because Condition is not evaluated until after the first iteration.A simple or structured statement.Example
repeat K := I mod J; I := J; J := K; until J = 0;See Also
Exceptions are handled within try...except statements.Grammar
TryExceptStmt -> try TryStatements except ExceptionBlock end ';' ExceptionBlock -> ExceptStatements | on Ident do Statement/','... [else Statement] [';'] end ';'Arguments
TryStatementsA sequence of statements (delimited by semicolons)ExceptStatementsA sequence of statements (delimited by semicolons)ExceptionBlockThe TryStatements contain code where an error can occur, while ExceptionBlock contain the code to handle any error that does occur. If an error occurs in the tryStatements, program control is passed to ExceptionBlock for processing. The initial value of exception is the value of the error that occurred in tryStatements. If no error occurs, ExceptionBlock are never executed. If the error cannot be handled in the ExceptionBlock associated with the TryStatements where the error occurred, use the raise statement to propagate, or rethrow, the error to a higher-level error handler.Either another sequence of statements (ExceptStatements), or a sequence of exception handlers, optionally followed by else statements.Example
try try raise 100; except on E do begin print 'except'; print E; end; end; finally print 'finally'; end;See Also
Sometimes you want to ensure that specific parts of an operation are completed, whether or not the operation is interrupted by an exception. In these situations, you can use a try...finally statement.Grammar
TryFinallyStmt -> try TryStatements finally FinallyStatements end ';'Arguments
TryStatementsA sequence of statements (delimited by semicolons)FinallyStatementsThe try-finally statement executes the statements in TryStatements (the try clause). If TryStatements finishes without raising exceptions, FinallyStatements (the finally clause) is executed. If an exception is raised during execution of TryStatements, control is transferred to FinallyStatements; once FinallyStatements finishes executing, the exception is re-raised. If an exception is raised but not handled in the finally clause, that exception is propagated out of the try...finally statement, and any exception already raised in the try clause is lost. The finally clause should therefore handle all locally raised exceptions, so as not to disturb propagation of other exceptions.Optional. Statements that are unconditionally executed after all other error processing has occurred.Example
try try raise 100; except on E do begin print 'except'; print E; end; end; finally print 'finally'; end;See Also
Creates new record type, class type or array type.Grammar
TypeStmt -> TypeIdent (RecordType|ClassType|ArrayType) RecordType -> record [ '(' Ancestor ')' ] MemberStatement /... end ';' ClassType -> class [ '(' Ancestor ')' ] MemberStatement /... end ';' ArrayType -> array ['[' Bounds/','... ']'] of TypeElement EnumType -> '(' Ident {'=' Number} /','... ']' Bounds -> Ident1 .. Ident2Arguments
TypeIdentName of the type.AncestorOptional. Name of the ancestor class type or ancestor record type.MemberStatementThe Type statement provides Object Pascal syntax for the Class Statements and Record statements. For example the following statementsOne or more statements that define the variables, properties, and methods of the class or record.Example 1
type TPoint = record X, Y: Integer; end; TMyClass = class(TObject) procedure ShowInfo; end; procedure TMyClass.ShowInfo; begin print 'info'; end;are equivalent toExample 2
record TPoint X, Y: Integer; end; class TMyClass(TObject) procedure ShowInfo; begin print 'info'; end; end;With the Type statements, you can create array types as well. For example, the following statement:Example 3
type TMyArray = array [3..5] of Integer;is equivalento toExample 4
record TMyArray var L = 3; var H = 5; var fItems[H - L]; procedure Initialize; var I: Integer; begin for I:=L to H do fItems[I - L] := 0; end; function GetItem(I: Integer): Integer; begin result := @ fItems[I - L]; end; procedure SetItem(I: Integer; Value: Integer); begin fItems[I - L] := Value; end; property Items[I: Integer]: Integer; read GetItem write SetItem; default; end;See Also
Creates new namespace.Grammar
UnitStmt->UnitName interface [UsesStmt] {VarStmt|ConstStmt|ClassStmt|FunctionStmt|ProcedureStmt} implementation {VarStmt|ConstStmt|ClassStmt|FunctionStmt|ProcedureStmt} [initialization StmtList] [finalization StmtList]Arguments
UnitNameThe unit statement provides Delphi unit syntax for the namespace statement.Name of namespace.Example
unit a; interface type TMyClass = class(TObject) procedure Proc(x: Integer); end; const x = 10; var z: TMyClass; y: Double; procedure P(u, v: Double); implementation procedure P(u, v: Double); begin writeln(u + v); end; procedure TMyClass.Proc(x: Integer); begin writeln(x); end; initialization writeln('start'); y := 1; writeln(y); P(3, 4); z := TMyClass.Create; z.Proc(100); finalization z.Free; writeln('fin'); end.
Uses statements are provided to facilitate the use of namespaces.Grammar
UsesStmt -> uses NamespaceName, /','... ';'Arguments
NamespaceNameName of a namespaceExample
uses Classes; var I, L = TList.Create; L.Add(2); L.Add(TObject.Create); L.Add(5); L.Add(7); for I:=0 to L.Count - 1 do print L[I];
Declares a variable.Grammar
VarStmt -> [class] [var] Variable [':' TypeIdent] ['['Subscripts']'][ = Value ] /,... ';' Subscripts -> Upperbound /','...Arguments
VariableThe name of the variable being declared.ValueThe initial value assigned to the variableClassOptional. The class keyword specifies a static (shared) field of a class. Can be used only inside of a class body.SubscriptsDimensions of an array variable.UpperboundUse the var statement to declare variables. These variables can be assigned values at declaration or later in your script.Upper bound. The lower bound of an array is always zero.Example 1
var A[30, 4]; var X = [10, 20, 30]; var Y: Integer; var Z: TObject = TObject.Create;You can use the var statement inside of a class body. In such case the statement declares a field of a class instance or a static (shared) field of the class.Example 2
class TMyClass(TObject) var A[10, 2], X; var Y = [100, 200, 300]; class var Z = 5; end;See Also
- Class Statements
/ul>
The while statement executes its constituent statement repeatedly, testing Condition expression before each iteration. As long as Condition returns True, execution continues.Grammar
WhileStmt -> while Condition do StatementArguments
ConditionA Boolean expression. If condition is undefined, condition is treated as false.StatementA simple or structured statement.Example
while Data[I] <> X do I := I + 1;See Also
The with statement is a shorthand for referencing the the fields, properties, and methods of an object.Grammar
WithStmt -> with Obj/','... do StatementArguments
ObjA variable reference denoting an objectStatementAny simple or structured statement.Example
with Form1 do begin Caption := 'My Form'; Height := 200; Width := 300; end;See Also
- Class Statements
/ul>