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

High

Return highest index of open array or enumerated

Declaration

Source position: system.fpd line 45

function High(

  Arg: TypeOrVariable

):TOrdinal;

Description

The return value of High depends on it's argument:

  1. If the argument is an ordinal type, High returns the highest value in the range of the given ordinal type.
  2. If the argument is an array type or an array type variable then High returns the highest possible value of it's index. For dynamic arrays, it returns the same as Length -1, meaning that it reports -1 for empty arrays.
  3. If the argument is an open array identifier in a function or procedure, then High returns the highest index of the array, as if the array has a zero-based index. If the array is empty, then -1 is returned.
  4. If the argument is a set type then it returns the highest value of the underlying ordinal type.

The return type is always the same type as the type of the argument (This can lead to some nasty surprises !).

Errors

None.

See also

Low

  

Return lowest index of open array or enumerated

Ord

  

Return ordinal value of an ordinal type.

Pred

  

Return previous element for an ordinal type.

Succ

  

Return next element of ordinal type.

Example

Program example80;

{ Example to demonstrate the High and Low functions. }

Type TEnum = ( North, East, South, West );
     TRange = 14..55;
     TArray = Array [2..10] of Longint;

Function Average (Row : Array of Longint) : Real;

Var I : longint;
    Temp : Real;


begin
  Temp := Row[0];
  For I := 1 to High(Row) do
     Temp := Temp + Row[i];
  Average := Temp / (High(Row)+1);
end;

Var A : TEnum;
    B : TRange;
    C : TArray;
    I : longint;

begin
  Writeln ('TEnum  goes from : ',Ord(Low(TEnum)),' to ', Ord(high(TEnum)),'.');
  Writeln ('A      goes from : ',Ord(Low(A)),' to ', Ord(high(A)),'.');
  Writeln ('TRange goes from : ',Ord(Low(TRange)),' to ', Ord(high(TRange)),'.');
  Writeln ('B      goes from : ',Ord(Low(B)),' to ', Ord(high(B)),'.');
  Writeln ('TArray index goes from : ',Ord(Low(TArray)),' to ', Ord(high(TArray)),'.');
  Writeln ('C index      goes from : ',Low(C),' to ', high(C),'.');
  For I:=Low(C) to High(C) do
    C[i]:=I;
  Writeln ('Average :',Average(c));
  Write ('Type of return value is always same as type of argument:');
  Writeln(high(high(word)));
end.
 

Documentation generated on: Sep 28 2017