Difference between revisions of "Var"

From Lazarus wiki
Jump to navigationJump to search
(corrected red links)
Line 1: Line 1:
 
{{Var}}
 
{{Var}}
  
Var is a [[Keyword|keyword]] used to mark the section where [[Variable|variables]] and their data [[Type|type]]s are declared. When used for a parameter of a [[Procedure|procedure]] or [[Function|function]] then '''var''' indicates the use of a [[Variable parameter|variable parameter]].
+
'''Var''' is a [[Keyword|keyword]] used to mark the section where [[Variable|variables]] and their data [[Type|type]]s are declared. When used for a parameter of a [[Procedure|procedure]] or [[Function|function]] then '''var''' indicates the use of a [[Variable parameter|variable parameter]].
 
   
 
   
 
Variables are typically declared at the beginning of a [[Program|program]], [[Procedure|procedure]], [[Function|function]] or [[Unit|unit]].
 
Variables are typically declared at the beginning of a [[Program|program]], [[Procedure|procedure]], [[Function|function]] or [[Unit|unit]].
  
<syntaxhighlight>var
+
<syntaxhighlight>
   age: integer;</syntaxhighlight>  
+
var
 +
   age: integer;
 +
</syntaxhighlight>  
  
 
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|comma]].
 
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|comma]].
  
<syntaxhighlight>var
+
<syntaxhighlight>
   FirstName, LastName, address: string;</syntaxhighlight>  
+
var
 +
   FirstName, LastName, address: string;
 +
</syntaxhighlight>
 +
 
 +
A '''var''' variable as a procedure or function parameter can bet used for a returnvalue:
 +
<syntaxhighlight>
 +
procedure foo( var v1: sometype; out v2: sometype; const v3: sometype )
 +
begin
 +
  v1 := v1 + v3; // input and return vlaue
 +
  v2 := v3; // only return value
 +
  v3 := myconst; // immutable... only input
 +
end;
 +
</syntaxhighlight>  
 +
 
  
 
== See also ==
 
== See also ==

Revision as of 14:04, 17 July 2016

Deutsch (de) English (en) español (es) suomi (fi) français (fr) русский (ru) 中文(中国大陆)‎ (zh_CN)

Var is a keyword used to mark the section where variables and their data types are declared. When used for a parameter of a procedure or function then var indicates the use of a variable parameter.

Variables are typically declared at the beginning of a program, procedure, function or unit.

var
  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.

var
  FirstName, LastName, address: string;

A var variable as a procedure or function parameter can bet used for a returnvalue:

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


See also