Delphi code error not understood

I am a total novice regarding Delphi. I am trying to build a package for eventual use in a C++ builder project (in which language I am not a novice).
I am using code that I have found for using Smart cards.
the following code fragment generates an error and I need assistance to understand why and correct it.
I am using Embarcadero RAD Studio 10.2 enterprise edition

var
  r : string;
  a : integer;
begin
  a := 1;
  while a <= Length(Input) do
    begin
    case Input[a] of
      #010       : if WantFormats then r := r + #10 else r := r + ' ';
      #013       : if WantFormats then r := r + #13 else r := r + ' ';
      #027       : if a < Length(Input) then
                     begin
                     Inc(a);
                     r := r + Extended[Ord(Input[a])+1];
                     end else r := r + ' ';
      #128..#255 : ; {<<<<<<<<< This line gerates the error }
      else r := r + Ascii[Ord(Input[a])+1];
      end;
    Inc(a);
    end;
Result := r;
end;


gives the following error message
[dcc32 Error] GsmHelper.pas(551): E2011 Low bound exceeds high bound

Open in new window

LVL 2
Roger AlcindorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert GOracle dbaCommented:
try it with ord(Input[a])

  case Ord(Input[a]) of
      10       : if WantFormats then r := r + #10 else r := r + ' ';
      13       : if WantFormats then r := r + #13 else r := r + ' ';
      27       : if a < Length(Input) then
                     begin
                     Inc(a);
                     r := r + Extended[Ord(Input[a])+1];
                     end else r := r + ' ';
      128..255 : ; {<<<<<<<<< This line gerates the error }
     else r := r + Ascii[Ord(Input[a])+1];
    end;

Open in new window

Geert GOracle dbaCommented:
might also depend on the definition of input

is it ansistring or string ?
Roger AlcindorAuthor Commented:
The error still persists even when no reference to Input is made and only the case range is used as per the code shown below ?


var
  r : string;
  a : integer;
begin
  a := 1;
  while a <10 do//<= Length(Input) do
    begin
      case a of //Input[a] of
      #128..#255 : ; {<<<<<<<<< This line gerates the error }
      end;
      Inc(a);
    end;
Result := r;
end;

Open in new window

Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Sinisa VukSoftware architectCommented:
In Delphi 10.2 you cannot use Ord(Input[a]) cause ansistring not exists anymore. All strings are double-byte char strings.
In last example should be:
var
  r : string;
  a : byte;
begin
  a := 1;
  while a <10 do
    begin
      case a of 
       128..255 : ;
      end;
      Inc(a);
    end;
Result := r;
end;

Open in new window


... better work with byte array... here is how to convert strings to byte array...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roger AlcindorAuthor Commented:
Thanks for identifying the problem How far back in RAD Studio versions would I need to go to find that  AnsiStrings did exist in Delphi ?
Sinisa VukSoftware architectCommented:
Not sure but think from 10.2 ... Event before it is not recommend to use, but starting from 10.2 - AnsiString is not recognized any more as such..
Here is more info ...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.