DelphiBasics
Dec
Procedure
Decrement an ordinal variable System unit
1 procedure Dec(var Variable Ordinal variable);
2 procedure Dec (var Variable Ordinal variable; Count Integer;
Description
The Dec procedure decrements the ordinal Variable parameter passed to it.
 
You can decrement :
 
Characters 
Non-floating number types 
Enumeration types 
Pointers 

 
The decrement is by the base size of the unit. For example, decrementing a Pointer will be by 4 bytes if the pointer points to Words.
 
Version 1 of Inc decrements by 1 unit.
 
Version 2 of Inc decrements by Count units.
 
Notes
Dec is equivalent in performance to simple subtraction, or the Pred procedure.

Count can be negative.
Related commands
IncIncrement an ordinal variable
PredDecrement an ordinal variable
SqrGives the square of a number
SqrtGives the square root of a number
SuccIncrement an ordinal variable
SuccIncrement an ordinal variable
SumReturn the sum of an array of floating point values
 Download this web site as a Windows program.




 
Example code : Decrementing characters, numbers and enumerations
type
  TSuit = (Hearts, Clubs, Diamonds, Spades);
var
  Character : char;
  Number    : Integer;
  Card      : TSuit;

begin
  // We can decrement characters
  Character := 'B';

  ShowMessage('Character : '+Character);
  Dec(Character);
  ShowMessage('Character-1 : '+Character);

  // We can decrement numbers
  Number := 23;

  ShowMessage('Number : '+IntToStr(Number));
  Dec(Number, 5);
  ShowMessage('Number-5 : '+IntToStr(Number));

  // We can decrement enumerations
  Card := Clubs;

  ShowMessage('Card starts at Clubs');
  Dec(Card);
  if Card = Hearts then ShowMessage('Card is now Hearts');
  if Card = Clubs then ShowMessage('Card is now Clubs');
  if Card = Diamonds then ShowMessage('Card is now Diamonds');
  if Card = Spades then ShowMessage('Card is now Spades');
end;
Show full unit code
  Character : B
  Character-1 : A
  Number : 23
  Number-5 : 18
  Card starts at Clubs
  Card is now Hearts
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page