DelphiBasics
Pred
Function
Decrement an ordinal variable System unit
 function Pred ( const Ordinal Value ) : Ordinal type;
Description
The Pred function decrements an ordinal value, and returns this value.
 
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 2 bytes if the pointer points to Words.
 
Notes
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

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 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);
  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');
end;
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 - 2016. All rights reserved.  |  Home Page