The New Ansi String Type

Differently from the past, the new AnsiString type string carries one further piece of information, the code page of the characters in the string. The DefaultSystemCodePage variable defaults to CP_ACP, the current Windows code page, but it could be modified by calling the special procedure SetMultiByteConversionCodePage. You can do this to force an entire program to work (by default) with characters in a given code page (that the operating system installation must support, of course).

36 This excludes the non-reference counted string types, which include the ShortString, WideString, and UCS4String types.

37 With byte arrays available (as covered in the next chapter) you should try to move to the more specific construct, although a RawByteString might let you migrate your existing code with less effort.

In general, instead, you'd either stick to the current code page or change it for individual strings, calling the SetCodePage procedure (introduced earlier while talking about characters and code pages). This procedure can be called in two different ways. In the first case, you change the code page of a string (maybe loaded by a separate file or socket) because you know its format. In the second case, you can call it to convert a given string (something that happens automatically when assigning a string to one of a different code page, as discussed later).

Although you can keep using the AnsiString type to have a more compact inmemory representation of strings, in most cases you'd really want to convert your code to using the new UnicodeString type. That is, keep your strings declared with the generic string type. Still, there are circumstances in which using a specific string type is necessary. For example, when loading or saving files, moving data from and to a database, using Internet protocols where the code must remain in an 8-bit per character format. In all those cases convert your code to use AnsiString38.

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