LMD ScriptPack Guide


Global Declarations


At the global declaration level script source-code (unit) can contain procedure and function declarations, global variable and constant declarations. The unit may also contain global statements block at the end:

 

var
  X, Y;
  Z = 7;
 
const
  Pi = 3.14;
 
procedure P(A; B);
var
  i, j;
  k = 3;
begin
  ShowMessage(+ B + F * Pi);
end;
 
function F;
begin
  Result := 7;
end;
 
begin
  ShowMessage('This is a global statement');
end;

 

There can be more than one var or const sections, moreover they can be placed between procedures/functions. The global statement block (begin/end) should reside at the end of the unit. The global statement block is optional and can be omitted. Just like for global variables, PasScript allows to specify initializers for local variables.

 

Unlike Delphi, the order of procedures/functions/variables/constants declarations is not meaningful, procedures/functions can refer to each other, unrelated to the declaration order.

 

Since PasScript is untyped language, no type specification is allowed in variables/parameters/functions declaration.

 

Procedure/function parameters are declared as a list of parameter names delimited with ";". By default, parameters have by-value semantic. var and out keywords can be used to denote parameters passed by reference; there are no difference between var and out parameters, two distinct keyword are just used to help writing self documented code. const keyword is used to denote read-only parameters. Parameter list can be empty. Here the examples of parameter declarations:

 

procedure P;   
procedure P(); 
procedure P(A);
procedure P(A; B; const C);
procedure P(A; var B; out C);

 

Implicit Result variable is accessible inside a function. This variable should be used to assign returning value to the function. This variable works just as simple local variable, you can read it value, assign a value or pass the Result variable by reference.

 

Script code can use Exit intrinsic function to immediately exit from the parent procedure or function. Run-time error will occurs if Exit function is used outside of any function or procedure (e.g. in global code).