May 2009 Developer's Poll

Use this forum for polls.

What string class do you use in your C++Builder 2009 component/library code?

(a) AnsiString
(b) WideString
No votes
(c) UnicodeString
(d) My own wrapper class
(e) Multiple classes (I maintain separate versions of the same code)
Total votes : 41

May 2009 Developer's Poll

Postby Damon » Wed Jun 10, 2009 9:14 pm

Thanks to Malcolm Smith for this month's question. Here's the motivation...

A key feature in C++Builder 2009 is the support of Unicode strings via the UnicodeString class. When designing a component or library that must work on multiple versions of C++Builder, one must decide whether to use AnsiString, WideString, or UnicodeString.

In component development, for example, you sometimes need to define BCB2009 properties as UnicodeString to best match assignment to other component properties, yet at the same time leave as AnsiString for older components.

One (unattractive) option is to maintain two versions of the same code, each version using a different string class. Another option is to create a custom wrapper class that automatically makes use of AnsiString, WideString, or UnicodeString depending on the BCB version (e.g., via #ifdef and typedef).


Damon Chandler
C++Builder Developer's Journal
User avatar
BCBJ Editor and Admin
BCBJ Editor and Admin
Posts: 285
Joined: Wed May 26, 2004 11:25 pm
Location: Stillwater, OK, USA

Re: May 2009 Developer's Poll

Postby rlebeau » Thu Jun 11, 2009 12:31 pm

I prefer to use the #ifdef approach to allow a single codebase cater itself to the capabilities of each compiler it runs on. That way, the logic is centralized, and it is easier to see where compiler differences exist. If multiple copies of source were used, one for each compiler, then you have the problem of having to keep them in sync when changes need to be made.

As for the wrapper class approach - I don't do it, party because 1) it is more work to implement and ensure it is a straight-drop-in everywhere Ansi/Wide/UnicodeString can be used; and 2) I've been porting my components to Pascal in order to support Delphi and C++ together, and using a wrapper class is not an option in that scenerio anyway.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
BCBJ Author
BCBJ Author
Posts: 1574
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Return to Polls

Who is online

Users browsing this forum: No registered users and 3 guests