From Free Pascal wiki
Jump to: navigation, search

Deutsch (de) English (en) español (es) suomi (fi) français (fr) 中文(中国大陆)‎ (zh_CN)

Var is a keyword that is used for two different purposes:

  • signify the start of a variable definition section
  • make a function or procedure parameter be passed by reference instead of passed by value

Variable Definition

Var is used to mark the section where variables and their data types are declared. Variables are typically declared at the beginning of a program, procedure, function or unit.

  age: integer;

If you are planning to use various variables of the same type, they can be grouped so they share the same type definition. The variables must be separated by a comma.

  FirstName, LastName, address: string;

Pass by Reference

When used before a parameter of a procedure or function var indicates that the parameter is a variable parameter. A variable parameter can be used to receive data from, as well as send data to, a procedure or function:

procedure foo( var v1: sometype; out v2: sometype; const v3: sometype )
  v1 := v1 + v3; // input and return value
  v2 := v3;      // only return value
  v3 := myconst; // immutable... only input

See also