System.Dec

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure Dec(var X: Integer); overload;
procedure Dec(var X: Integer; N: Integer); overload;

Properties

Type Visibility Source Unit Parent
procedure public System.pas System System

Description

Decrements a variable by 1 or N.

In Delphi code, Dec subtracts one or N from a variable.

X is a variable of an ordinal type (including Int64), or a pointer type if the extended syntax is enabled.

N is an integer-type expression.

X decrements by 1, or by N if N is specified, for example:

  • Dec(X) corresponds to the statement X := X - 1
  • Dec(X,N) corresponds to the statement X := X - N.

On some platforms, Dec may generate optimized code, especially useful in tight loops.

If X is a pointer type, it decrements X by N times the size of the type pointed to. Thus, given:

 type
   PMyType = ^TMyType;

and

 var
   P: PMyType;

The statement Dec(P) decrements P by SizeOf(TMyType).

Warning: Do not use Dec on ordinal-type properties if the property uses a write procedure.

See Also

Code Examples