Delphi 2007 and Delphi 2009+ difference in string types

CodeGear Delphi 2007

In Delphi 2007AnsiString was the default string type used for general-purpose string manipulation. This means variables declared simply as string were compiled as AnsiString. This changed in Delphi 2009+, where string became an alias for UnicodeString.

AnsiString in Delphi 2007:
  • Character Size: Each character (AnsiChar) in an AnsiString is an 8-bit (1-byte) value.
  • Encoding: The interpretation of these bytes depends on the operating system's current active code page (e.g., Windows-1252, or specific locales like code page 936 for simplified Chinese).
  • Length: AnsiString was dynamically allocated and limited only by available memory, unlike the older ShortString that was limited to 255 characters.
The primary distinction in Delphi 2009 and later is the shift to Unicode.
  • string is an alias for UnicodeString (UTF-16, 2 bytes per character).
  • AnsiString still exists but is used primarily for backward compatibility or interfacing with non-Unicode systems/APIs.

Delphi and Unicode, Marco Cantù, December 2008

No comments:

Post a Comment