delphidelphi-5delphi-10.4-sydney

"Low Bound Exceeds High Bound" error in Delphi 10


Currently I am in the process of migrating an application from Delphi 5 to Delphi 10. The below switch case works fine in Delphi 5 but gives

"Low Bound Exceeds High Bound" 

error in Delphi 10 during compilation. If I change the value from #128 to #127 then everything works fine. I am not sure why using #128 gives an error whereas using #127 works fine.

var Src : PChar;
...
case Src^ of
  #128..#255 :
    begin
    end;
end;

Solution

  • I don't know why the code you show doesn't work. I fear it is a bug! Anyway, to have it compile, you can write it like this:

    var Src : PChar;
    ...
    case Src^ of
      #128, #129..#255 :
        begin
        end;
    end;
    

    This will have the same effect. You can also write:

    case Ord(Src^) of
      128..255 :
        begin
        end;
    end;
    

    But this second variation is annoying if you have many other cases where you have constant char. You have to modify each one by adding and Ord().

    You should also have a look at the effect of {$HIGHCHARUNICODE} directive.

    By the way: This kind of code is - maybe - the sign that you forgot that in Delphi 5 characters are 8 bit ANSI while for Delphi 2009 and upward, the characters are 16 bit.