Decrement an ordinal variable System unit
 function Pred ( const Ordinal Value ) : Ordinal type;
The Pred function decrements an ordinal value, and returns this value.
You can decrement :
Non-floating number types 
Enumeration types 

The decrement is by the base size of the unit. For example, decrementing a Pointer will be by 2 bytes if the pointer points to Words.
Pred is equivalent in performance to simple subtraction, or the Dec procedure.
Related commands
Dec Decrement an ordinal variable
Inc Increment an ordinal variable
Sqr Gives the square of a number
Sqrt Gives the square root of a number
Succ Increment an ordinal variable
Sum Return the sum of an array of floating point values
 Author links

 Download this web site as a Windows program.

Example code : Decrementing characters, numbers and enumerations
  TSuit = (Hearts, Clubs, Diamonds, Spades);

  Character : char;
  Number    : Integer;
  Card      : TSuit;

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

  ShowMessage('Character : '+Character);
  Character := Pred(Character);
  ShowMessage('Character-1 : '+Character);

  // We can decrement numbers
  Number := 23;

  ShowMessage('Number : '+IntToStr(Number));
  Number := Pred(Number);
  ShowMessage('Number-1 : '+IntToStr(Number));

  // We can decrement enumerations
  Card := Clubs;

  ShowMessage('Card starts at Clubs');
  Card := Pred(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');
Show full unit code
   Character : B
   Character-1 : A
   Number : 23
   Number-1 : 22
   Card starts at Clubs
   Card is now Hearts
Delphi Programming Neil Moffatt 2002 - 2020. All rights reserved.  |  Home Page