[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'System' (#rtl)

Dec

Decrease value of variable

Declaration

Source position: system.fpd line 38

procedure Dec(

  var X: TOrdinal

);

procedure Dec(

  var X: TOrdinal;

  Decrement: TOrdinal

);

Description

Dec decreases the value of X with Decrement. If Decrement isn't specified, then 1 is taken as a default.

Dec can be used on typed pointers: in that case it decreases the value with Decrement the size of the type the pointer points to. This works independently of the setting of the $POINTERMATH directive.

Errors

A range check can occur, or an underflow error, if an attempt is made to decrease X below its minimum value.

See also

Inc

  

Increase value of integer variable

Example

Program Example14;

{ Program to demonstrate the Dec function. }

Var
  I  : Integer;
  L  : Longint;
  W  : Word;
  B  : Byte;
  Si : ShortInt;

begin
 I:=1;
 L:=2;
 W:=3;
 B:=4;
 Si:=5;
 Dec (i);    { i:=0  }
 Dec (L,2);  { L:=0  }
 Dec (W,2);  { W:=1  }
 Dec (B,-2); { B:=6  }
 Dec (Si,0); { Si:=5 }
end.

Documentation generated on: May 14 2021