The new large Char type is still an ordinal type, so you can use Inc and Dec on it, write for loops with a Char counter, and the like.
22 WideChar is simply a 16-bit unsigned integer without any specific character encoding scheme attached. When used in a UnicodeString, though, a WideChar can be interpreted as a surrogate, so that two WideChar can be bound together to represent a single Unicode code point. More about this in the section "UnicodeString and Unicode".
These code snippets are part of different methods of the TestChar example. The only thing that might get you into some (limited) trouble is when you are declaring a set based on the entire Char type: var
CharSet = set of Char; begi n charSet := ['a', 'b', 'c']; if 'a' in charSet then
In this case the compiler will assume you are porting existing code to Delphi 2009, decide to consider that Char as an AnsiChar (as a set can only have 256 elements at most24) and issue a warning message:
W1050 WideChar reduced to byte char in set expressions. Consider using 'CharlnSet' function in 'SysUtils' unit.
The code will probably work as expected, but not all existing code will easily map, as it is not possible to obtain a set of all the characters any more. If this is what you need, you'll have to change your algorithm (possibly following what's suggested by the warning, but I'll get to that in ample detail in the section "Watch Out for Set of Char" of the next chapter, focused on porting existing code to Delphi 2009).
If what you are looking for, instead, is to suppress the warnings (compiling the five lines of code above causes two of them) you can write:
var charSet: set of AnsiChar; // suppress warning begi n charSet := ['a', 'b', 'c'];
if AnsiChar('a') in charSet then // suppress warning
23 As with the string type, the Char type is mapped to a specific data type in a fixed and hard-coded way. Developers have asked for a compiler directive to be able to switch, but this would cause a nightmare in terms of QA, support, package compatibility, and much more. You still have a choice, as you can convert your code to use a specific type, such as AnsiChar.
24 If you try declaring a large set of, say, a range of Integers (like I did in some commented code of the CharTest example) you'll get the error:
E2028 Sets may have at most 256 elements.
Was this article helpful?
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.