Back

Increment and Decrement


Inc(Variable);
procedure Inc(var X [ ; N: Longint ] );

X increments by 1, or by N if N is specified

---

Dec(Variable);
procedure Dec(var X[ ; N: Longint]);

X decrements by 1, or by N if N is specified.

---

Examples:

Dec(FCount);

procedure TForm1.Button1Click(Sender: TObject);
var I : Integer;
begin
    I := 1;
    Label1.Caption := IntToStr(I);
    Inc(I);
    Label2.Caption := IntToStr(I);
end;

I starts at the number 1, then I is incremented to 2.

To increment by an amount you can do it like this:

var Form1: TForm1; I : Integer;
implementation {$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
      Inc(I, 30);
      Label1.Caption := IntToStr(I);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
      I := 0;
end;

Everytime Button1 is clicked on I is icreased by 30.
 

This will decrement I by 30:
 

var Form1: TForm1; I : Integer;
implementation {$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
      Dec(I, 30);
      Label1.Caption := IntToStr(I);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
      I := 0;
end;
 


Back

Copyright © 1998-2001 James M Sandbrook & Sandbrook Software. All rights reserved.
Do not duplicate or redistribute in any form.