[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'System' (#rtl)

Ord

Return ordinal value of an ordinal type.

Declaration

Source position: system.fpd line 57

function Ord(

  X: TOrdinal

):LongInt;

Description

Ord returns the Ordinal value of a ordinal-type variable X.

Historical note:

Originally, Pascal did not have typecasts and ord was a necessary function in order to do certain operations on non-integer ordinal types. With the arrival of typecasting a generic approach became possible, making ord mostly obsolete. However ord is not considered deprecated and remains in wide use today.

Errors

None.

See also

Chr

  

Convert byte value to character value

Succ

  

Return next element of ordinal type.

Pred

  

Return previous element for an ordinal type.

High

  

Return highest index of open array or enumerated

Low

  

Return lowest index of open array or enumerated

Example

Program Example45;

{ Program to demonstrate the Ord,Pred,Succ functions. }

Type
  TEnum = (Zero, One, Two, Three, Four);

Var
  X : Longint;
  Y : TEnum;

begin
  X:=125;
  Writeln (Ord(X));  { Prints 125 }
  X:=Pred(X);
  Writeln (Ord(X));  { prints 124 }
  Y:= One;
  Writeln (Ord(y));  { Prints 1 }
  Y:=Succ(Y);
  Writeln (Ord(Y));  { Prints 2}
end.

Documentation generated on: May 14 2021