Parameters

Prior | Next

Passing Parameters
ESPL enables you to pass parameters to functions and procedures.  The parameters can be any variable or value.

By default, parameters are passed by value, which means the function or procedure operates on a local copy of the variable used in the parameter list.  The original variable in the call will not be changed by the procedure or function. Example:

procedure Test(s: string);
begin
  s := s + 'More Characters';
end;

var
  MyString : string;
begin
  MyString := 'Hello';
  Test( MyString );
  writeln( MyString ); {MyString was not changed by what happened in Test}
end;

However, parameters can be passed by reference so that the original variable is changed.  To pass a variable by reference, use the keyword var in the procedure's or function's parameter list.  Example:

procedure Test(var s: string);
begin
  s := s + 'More Characters';
end;

var
  MyString : string;
begin
  MyString := 'Hello';
  Test( MyString );
  writeln( MyString ); {Now, MyString will be changed by the Test procedure}
end;

Prior | Next