E2001 Ordinal type required

Viewed 1044

Here facing some errors on Ordinal type required, please help me to check it out from the following code:

Extracted from comments:

Program Test;    
{$APPTYPE CONSOLE}    
Type
  TResourceSet = set of 0..127;
var
  N : TResourceSet;
  i : Int64;
begin
  i := 127;
  N := N + [i];  // E2001 Ordinal type required
end.
1 Answers

64 bit types cannot be used in set operations. Hence the compiler error E2001 Ordinal type required.

I cannot find any documentation as to why the compiler disallows that. Some details in Ordinal Types states that Int64 does not qualify for use with certain ordinal functions.

Anyway in order to make it work you can declare the type as Integer or copy your 64 bit integer to a byte.

Program Test;    
{$APPTYPE CONSOLE}    
Type
  TResourceSet = set of 0..127;
var
  N : TResourceSet;
  i : Int64;
  j : Byte;
  k := Integer;
begin
  i := 127;
  j := i;
  k := i;
  N := N + [j];  // Ok
  N := N + [k];  // ok
end.

Or, as suggested by @Andreas, use a type cast:

N := N + [Byte(i)];
Related