I am wanting to port several large apps from Delphi 2006 to XE. The reasons are not so much to do with Unicode, but to take advantage of (hopefully) better IDE stability, native PNG support, more components, less VCL bugs, less dependence on 3rd party stuff, less ribbing from you guys, etc. Some of the apps might benefit from Unicode, but that's not a concern at present. At the moment I just want to take the most direct route to getting them to compile again.
As a start, I have changed all ambiguous string declarations, i.e. string to AnsiString or ShortString, char to AnsiChar and pChar to pAnsiChar and recompiled with D2006. So far so good. Nothing broke.
My question is: Where to from here? Assuming I just present my sources to the XE compiler and light the touch paper, what is likely to be the big issue?
For example,
var
S : AnsiString ;
...
MainForm.Caption := S ;
Will this generate an error? A warning? I'm assuming the VCL is now Unicode, or will XE pull in a non-Unicode component, or convert the string? Is it in fact feasible to keep an app using 8-bit strings in XE, or will there be too many headaches?
If the best/easiest way to go is to Unicode, I'll do that, even though I won't be using the extended characters, at least in the near future anyway.
The other thing that I wonder about is 3rd party stuff. I guess I will need to get updated versions that are XE-compatible.
Any (positive!) comment appreciated.
The VCL is completely Unicode now, so the code you showed will generate a compiler warning, not an error, about an implicit conversion from
AnsiString
toUnicodeString
. That is a potentially lossy conversion if theAnsiString
contains non-ASCII characters (which the compiler cannot validate). If you continue usingAnsiString
, then you have to do an explicit type-cast to avoid the warning:You are best off NOT Ansi-fying your code like this. Embrace Unicode. Your code will be easier to manage for it, and it will be more portable to future versions and platforms. You should restrict
AnsiString
usage to just those places where Ansi is actually needed - network communications, file I/O of legacy data, etc. If you want to save memory inside your app, especially if you are using ASCII characters only, useUTF8String
instead ofAnsiString
. UTF-8 is an 8-bit encoding of Unicode, and conversions betweenUTF8String
andUnicodeString
are loss-less with no compiler warnings.