For backward compatibility reasons, all 2-digit string literals are parsed as AnsiChar by default, so that a developer like me living in Europe (or, more technically, having the same code page setting as me) will see the Euro currency symbol is displayed in the string. Actually, by executing the statement:

| Log (strl + ' - ' + IntToStr (Ord (strl[l]))); I'll get the output: | € - 8364

In other word, the literal is treated like an AnsiChar and converted to the proper Unicode code point. If you want to fully move to Unicode, though you might not like this behavior, as you'll never know how a given literal is going to be interpreted. That's why CodeGear introduced in Delphi 2009 a new compiler directive: | {$HIGHCHARUNICODE <ON|OFF>}

This directive determines how literal values between #$80 and #$FF are treated by the compiler. What I discussed earlier is the effect of the default option (OFF). If you turn it on, the same program will produce this output: | - l28

The number is interpreted as an actual Unicode code point and the output will contain a non-printable control character. Another option to express that specific code point (or any Unicode code point below #$ffff) is to use the four-digits notation: | strl := #$0080;

This is not interpreted as the Euro currency symbol regardless of the setting of the $highcharunicode directive.

What is nice is that you can use the four digits notation to express far eastern characters, like the following two Japanese characters: | strl := #$3042#$3044;

displayed47 as (along with their Integer representation):

You can also use literal elements over #$FFFF that will be converted to the proper surrogate pair.

Finally notice that for string literals, the code page is taken from the compiler options, which you can modify for a specific project, and not from the system code page of the computer on which you are compiling or executing the program.

47 fc translates to "meeting" according to BabelFish, but I'm not 100% sure where I originally found it.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment