durumdara
durumdara

Reputation: 3473

Delphi XE3: Chr Ansi Version?

I have my own D6 pas library with crypto functions. Today I tried to use it under XE3, and I found many bugs in it because of unicode. I tried to port to AnsiString, but I failed on chr(nnn) which was 8 bit limited under Delphi6.

I'm trying to explain the problem:

    Str := chr(hchar);
    AStr := Str;

Str - string; AStr - ansistring.

When the hchar was 216 (diamater), then AStr changed to "O", what is Ascii 79... And I lost the original value at this moment.

Is there any function for Ansi Chr? For example: "AChr(xxxx)"

Or I need to change my code to not use Strings in the inner section, only bytes and later convert these bytes to AnsiString?

Thanks for any suggestion, help, info!

dd

Upvotes: 3

Views: 4114

Answers (1)

David Heffernan
David Heffernan

Reputation: 612993

You can write AnsiChar(SomeOrdinalValue) to make an AnsiChar with a specific ordinal. So your code should be:

AStr := AnsiChar(hchar);

The problem with the code in the question is that you converted to UTF-16 and back.

It would seem to me that strings are the wrong type for your crypto code. Use a byte array, TBytes.

Upvotes: 5

Related Questions