views:

1783

answers:

4

I'm getting some weird behaviour recompiling some applications in 2009 that used widestrings at various points.

In a Delphi 2009 App is Widestring identical to String?

+15  A: 

No - WideString is basically a wrapper for the COM BSTR type. You need it if you're working with COM. "String" in Delphi 2009 can hold unicode characters, but it's NOT the same as WideString. For example, WideStrings aren't reference counted, while 'string' is.

You should use "string" wherever possible, and only use WideString for COM interop or dealing with legacy libraries.

Roddy
+6  A: 

It seems the answer is here:

The most dramatic change in Delphi 2009 is that the “string” type is now an alias for UnicodeString instead of AnsiString.

haggai_e
+2  A: 

See this paper by Marco Cantu which outlines the workings of string (i.e. UnicodeString) in Delphi 2009:

"White Paper: Delphi and Unicode"

http://dn.codegear.com/article/38980

Basically, it's what Roddy said, but takes 27 pages to go into detail.

moodforaday
+4  A: 

One other important thing to note is the performance difference.

In Marco Cantu's White Paper (referred to in moodforaday's answer) says:

"WideString was (and still is) not reference counted and is extremely poor in terms of performance and flexibility (for example, it uses the Windows global memory allocator rather than the native FastMM4)."

Almost every upgrade guide for Delphi 2009 I've seen recommends you convert all WideStrings to Strings.

lkessler