Starts the definition of a section of data variables
1   Var
    Name1 : Type;
2   Var
    Name1 : Type = Expression1;
3   Name (Var Var1 : type {;...});
The Var keyword is used to start a section of variable definitions.
The section is terminated by the next keyword in a program.
Within the section, one or more variables may be defined. These can be of any data type.
1.Variables with no initial value
These are defined with a given type, such as string or Integer but with no assigned default initial value.
2.Variables with an initial value
These are defined with a given type, such as string or Integer with an assigned initial value. Only global variables may be initialised.
3.Variable routine parameters
When passing data to a routine (function or procedure), you can prefix the parameter definition with Var if the variable itself is to be updated by the routine. This allows a caller to pass data to a routine that will be enriched by the routine.
Related commands
Const Starts the definition of fixed data values
Function Defines a subroutine that returns a value
Out Identifies a routine parameter for output only
Procedure Defines a subroutine that does not return a value
Type Defines a new category of variable or process
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Defining local and parameter variables
Var  // Local variables
  apples, bananas : Integer;
  // Initialise our fruit counts
  apples  := 1;
  bananas := 1;

  // Show their initial values
  ShowMessage('Apples  = '+IntToStr(apples));
  ShowMessage('Bananas = '+IntToStr(bananas));

  // Increment them in the UpdateCounts routine
  UpdateCounts(apples, bananas);

  // Show their new values - only Bananas will be updated
  ShowMessage('Apples  = '+IntToStr(apples));
  ShowMessage('Bananas = '+IntToStr(bananas));

// A procedure to increment the passed parameter values
procedure TForm1.UpdateCounts(count1: Integer; Var count2: Integer);
  // Increment both passed parameter values
Show full unit code
   Apples  = 1
   Bananas = 1
   Apples  = 1
   Bananas = 2
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page