How do I port characters expressed as decimals (#0, #1, #9, #10, #13, #32, #128, #255) in Delphi 7 to Delphi Unicode? Some documents (such as ‘Delphi in a Unicode world’ from Embarcadero) only says that they should be replaced with the actual character. For example instead of #128 I should use ‘€’. But what would you do with #0??? Or #9? Or #13?
Update:
It looks like this is a tricky question. Somebody stated here that all chars under 128 remain unchanged. However, ‘Delphi in a Unicode world’ states otherwise. So, there is a way to use something like #9 in Delphi XE or porting the code from Delphi 7 to Delphi Unicode involves massive code changes?
The low half of ANSI codes [#0..#127] does not change after conversion to Unicode, so you should not bother about it. The high half [#128..#255] is more complicated. The compiler interprets lines
depending on {$HIGHCHARUNICODE} directive
#200 is ‘И’ on Win1251 codepage. The Unicode codepoint for ‘И’ is $418.
On the other hand, in Unicode #200 is ‘È’. Win1251 does not have ‘È’ character and Unicode -> Win1251 conversion transforms it to ‘E’ which is #$45 for all ANSI codepages.
With {$HIGHCHARUNICODE OFF} the compiler interprets #128..#255 characters as ANSI characters depending on system codepage and, if necessary, converts them to unicode codepoints.
With {$HIGHCHARUNICODE ON} the compiler interprets #128..#255 characters as Unicode codepoints and, if necessary, converts them to ANSI characters with possible loss.
Update
I see now the problem code from the Nick’s article that works wrong on Unicode Delphi:
but that is an example of wrong
FillCharprocedure usage;FillCharjust fills the destination buffer with bytes (BTW only the first half of Buf in the above example) and ignores all the new Unicode stuff.FillCharshould be renamed by FillBytes now, and forbidden to use a character (#9) for the third argument.