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


Return highest index of open array or enumerated


Source position: system.fpd line 45

function High(

  Arg: TypeOrVariable



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 !).



See also



Return lowest index of open array or enumerated



Return ordinal value of an ordinal type.



Return previous element for an ordinal type.



Return next element of ordinal type.


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;

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

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

  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
  Writeln ('Average :',Average(c));
  Write ('Type of return value is always same as type of argument:');

Documentation generated on: Mar 17 2017