[next] [prev] [prev-tail] [tail] [up]

#### High

Declaration:
  Function High (Type identifier or variable reference) : Ordinal;
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.
  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.

  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 (531), Ord (542), Pred (548), Succ (583)

Listing: refex/ex80.pp

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.

[next] [prev] [prev-tail] [front] [up]