RAD Studio VCL Reference
System.Inc Function

Increments an ordinal value by one or N.

procedure Inc(var X); overload;
procedure Inc(var X; N: Longint); overload;
Inc( X);
Inc( X, Longint N);

In Delphi code, Inc adds one or N to the variable X. 

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 increments by 1, or by N if N is specified; that is, Inc(X) corresponds to the statement X := X + 1, and Inc(X, N) corresponds to the statement X := X + N. On some platforms, Inc may generate optimized code, especially useful in tight loops. 

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

  PMyType = ^TMyType;


  P: PMyType;

the statement Inc(P) increments P by SizeOf(TMyType).

Warning: You can't use Inc on properties because it modifies the parameter.
Note: Inc(S, I) where S is a ShortInt and I is a number greater than 127 will cause an EIntOverFlow exception to be raised if range and overflow checking are on. In Delphi 1.0, this did not raise an exception.

Delphi Examples: 

This example requires two buttons and two text fields.  The
text fields can be set to any integer and long integer value.
Click the buttons to execute Inc.
procedure TForm1.Button1Click(Sender: TObject);
  IntVar: Integer;
  IntVar := StrToInt(Edit1.Text);
  Edit1.Text := IntToStr(IntVar);       { IntVar := IntVar + 1 }

procedure TForm1.Button2Click(Sender: TObject);
  LongintVar: Longint;
  LongintVar := StrToInt(Edit2.Text);
  Inc(LongintVar, 5);
  Edit2.Text := IntToStr(LongintVar);   { LongintVar := LongintVar + 5 }


Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!