Name

Pred Function

Syntax

function Pred(const Value): Ordinal type;

Description

The Pred function returns the predecessor of an ordinal value, usually an enumerated value. That is, it returns the enumerated value whose ordinal value is one less than Value. Pred is not a real function.

Tips and Tricks

  • Dec, Pred, and subtraction by one have similar performance, so choose the one that you find most clear and easy to read.

  • Calling Pred(Low( SomeType )) raises runtime error 4 (ERangeError). Without overflow checking, though, Pred returns a value with the desired ordinal value, even though that value is not valid for the type.

Example

type TDay =
 (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday);
var
  Day: TDay;
begin
  ...
  Day := Pred(Day);
  ...

See Also

Dec Procedure, High Function, Inc Procedure, Low Function, Succ Function, $OverflowChecks Compiler Directive, $Q Compiler Directive

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.