Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 317
durumdara Avatar asked Feb 07 '26 05:02

durumdara


1 Answers

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.

like image 192
David Heffernan Avatar answered Feb 09 '26 09:02

David Heffernan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!