Board index » cppbuilder » Aggravating CString to Ansi String--help

Aggravating CString to Ansi String--help


2007-04-16 02:25:04 AM
cppbuilder106
We move a lot of code between VS2005 and BDS2006 and spend hours converting
CString stuff to Ansi and back...can we modify Ansi to add .Format(),
.Left(),.Right(),.Mid() and [n-1] to its class or is it a namespace, if so
can we modify that????THanks in advance.
 
 

Re:Aggravating CString to Ansi String--help

ActuaryOne wrote:
Quote
We move a lot of code between VS2005 and BDS2006 and spend hours converting
CString stuff to Ansi and back...
So, you want to make your code portable between VC and BDS?
And your code is already VC?
Quote
can we modify Ansi to add .Format(),
.Left(),.Right(),.Mid() and [n-1] to its class or is it a namespace, if so
can we modify that?
AnsiString already has a Format() member, so modifying AnsiString is
probably not the best solution.
If it were me, I'd look into creating a BDS version of CString,
derived from AnsiString. That way the code remains VC but compiles on
BDS. (Or the other-way-round, create a VC AnsiString based on CString)
Looks like a pretty good discussion in this thread:
groups.google.com/group/borland.public.cppbuilder.language/browse_thread/thread/7702b5a79a13236a
tinyurl.com/2e6mez
I would also add this admonishment about deriving from AnsiString:
tinyurl.com/33mm5l
 

Re:Aggravating CString to Ansi String--help

"ActuaryOne" < XXXX@XXXXX.COM >wrote:
Quote
We move a lot of code between VS2005 and BDS2006 and spend hours converting
CString stuff to Ansi and back...can we modify Ansi to add .Format(),
.Left(),.Right(),.Mid() and [n-1] to its class or is it a namespace, if so
can we modify that????THanks in advance.


There is no need for that. There is already CString like class based on std::string which is portable between VC and BDS.
Take a look here:
www.codeproject.com/string/stdstring.asp
 

{smallsort}

Re:Aggravating CString to Ansi String--help

"ActuaryOne" < XXXX@XXXXX.COM >writes:
Quote
We move a lot of code between VS2005 and BDS2006 and spend hours converting
CString stuff to Ansi and back...can we modify Ansi to add .Format(),
.Left(),.Right(),.Mid() and [n-1] to its class or is it a namespace, if so
can we modify that????THanks in advance.
You don't want to modify the interface of a 3rd party library, because
then you become a code maintainer for something you do not control.
That's a position in which nobody should want to be, and which people
should actively strive to avoid.
I'm thinking you'd be best off with your own facade class that holds a
CString or AnsiString depending on platform, and implements its
interface by forwarding all calls into that aggregated string. For
features that the string lacks, you can simulate it. That way your
class has the same interface on all platforms, and if implemented
correctly will have the same behavior.
Or you could use an intermediate string class like std::string, and
leave the platform-specific strings only in your GUI code, which is
already library-specific. (VCL code uses AnsiStrings, the rest of
your code uses std::string, etc.)
--
Chris (TeamB);
 

Re:Aggravating CString to Ansi String--help

"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
Quote
If it were me, I'd look into creating a BDS version of CString,
derived from AnsiString.
You can't derive a new class from AnsiString (or WideString, Variant,
or a number of other special RTL classes). The compiler won't allow
it, as the classes are marked so as to not allow derivitives to ensure
compatibility with Delphi. You could encapsulate an AnsiString
variable, though.
Gambit
 

Re:Aggravating CString to Ansi String--help

Darko Miletic wrote:
Quote

There is no need for that. There is already CString like class based on std::string which is portable between VC and BDS.

Take a look here:

www.codeproject.com/string/stdstring.asp


I know this is an old thread but has anybody had any success getting
CStdString to compile in BDS???????
It would solve a bundle of problems, and it works well in VC, I just
can't get it to compile. Guess I'm getting senile in my old age ;)