AnsiString default for string type in Embarcadero C ++ Builder?

I inherited an old Borland C ++ Builder application which now needs to be migrated to the new development tool. The suggested way is with Embarcadero C ++ Builder and from my initial tests it looks pretty smooth.

I have one problem to which I hope there is a simple solution:

The application analyzes a large number of text files. These files are based on ANSI and this will never change, hence ANSI and ANSI. The main problem I have is that with Embarcadero C ++ the type is string

now UnicodeString

instead AnsiString

(as it was in Borland C ++ Builder).

Using Unicode in this application is not an option - the files it works with are ANSI formatted. Changing the code to use AnsiString

(and similar) is doable, but I'd prefer as it uses a lot of constructs TStringList

(and similar).

So my question is, is there a config or compiler option or something I can use to tell Embarcadero to use System.AnsiString

as a definition for string

instead System.UnicodeString

?

This is probably a long shot, but in RAD Studio XE (which is an older version that I borrowed to do some tests) the documentation says "The default type is string

now a Unicode string" which means it can be changed. This is however rephrased in the documentation for the current version (XE8), so ...

+3


source to share


3 answers


I inherited an old Borland C ++ Builder application which now needs to be migrated to the new development tool. Suggested way: Embarcadero C ++ Builder

Yes. They are actually the same product. Borland created a subsidiary company called CodeGear to manage developer tools (Delphi, C ++ Builder, etc.) and then Embarcadero later bought CodeGear.

The main problem is that with Embarcadero C ++, the type string is now UnicodeString and not AnsiString (as it was in Borland C ++ Builder).

string

(lowercase s) refers to the STL class std::string

, which is still at the level char

. You are thinking of the C ++ Builder alias System::String

now mapped to System::UnicodeString

instead of System::AnsiString

(this change was made in C ++ Builder 2009 when it was introduced UnicodeString

). However, AnsiString

it still exists and can be used directly.

Using Unicode in this application is not an option - the files it works with are ANSI formatted.

Then don't use UnicodeString

to process them. Keep using AnsiString

.



Changing the code to use AnsiString (and similar) is doable, but I would prefer it as it uses a lot of TStringList (and similar) constructs.

That, on the other hand, would be a problem, yes. Most RTL only support UnicodeString

. Therefore, the code using TStringList

must be rewritten, for example using TList<AnsiString>

or std::vector<AnsiString>

(unless the code is using properties TStringList::(Comma|Delimited)Text

, in which case you have a big rewrite). However, for parsing code, AnsiString

many of the old RTL functions AnsiString

have been moved to a separate block System.AnsiStrings

, so you can add #include <System.AnsiStrings.hpp>

to your code to achieve them.

So my question is, is there a config or compiler option or something I can use to tell Embarcadero to use System.AnsiString as the definition for the string instead of System.UnicodeString?

Not. And if you think about it, it becomes a big deal to implement them. Multiple copies of RTL / VCL / FMX frameworks, 2 for each supported OS platform. And a lot of internal code needs to be IFDEF'ed to handle the differences between Ansi / Unicode processing logic. It is not realistic or cost effective for them (and too late at this stage, especially considering that it is AnsiString

not supported on mobile OS platforms - although there is a third-party patch to re-enable it).

This is probably a long shot, but in RAD Studio XE (which is an old version that I borrowed to do some tests), the documentation says "By default, the type string is a Unicode string", which implies that this can be changed.

No, this cannot be changed. RTL / VCL / FMX frameworks are now Unicode. But that doesn't require your code to be Unicode as well. Only in places where you need to interact directly with RTL / VCL / FMX. The rest of your code can continue to use AnsiString

(or even std::string

) as needed.

+4


source


Maybe I have bad news. They always talk about migration, nowhere about a quick fix.

http://docwiki.embarcadero.com/RADStudio/XE3/en/Enabling_Applications_for_Unicode http://docwiki.embarcadero.com/RADStudio/XE3/en/Enabling_C%2B%2B_Applications_for_Unicode



Well ... I hate Strings at Borland. Who the hell came up with their number from 1 instead of 0 ?!

+1


source


AnsiString -s can be easily converted to UnicodeString . This is how I processed the conversion. Old C ++ Builder 2007 code:

void __fastcall TFormVidya::lbEntData(TWinControl *Control, int Index, AnsiString &Data)
{
    if(FEntNameSto) {
        char *pc;
        int len=FEntNameSto->PeekValue(Index,&pc);
        Data.printf("DB %.*s",len,pc);
    } else Data.sprintf("MOCK %d!",Index);
}

      

Converted for C ++ Builder XE2:

void __fastcall TFormVidya::lbEntData(TWinControl *Control, int Index, UnicodeString &Data)
{
    if(FEntNameSto) {
        char *pc;
        int len=FEntNameSto->PeekValue(Index,&pc);
        AnsiString astr;
        astr.printf("DB %.*s",len,pc);
        Data=astr;
    } else Data.sprintf(L"MOCK %d!",Index);
}

      

The essence is to appoint AnsiString to a UnicodeString : Data=astr;

.

Also, the help page ms-help: //embarcadero.rs_xe2/libraries/System.UnicodeString.html (the one that says "By default, variables declared as type String are UnicodeString.") Also says " Despite its name, UnicodeString can represent both ANSI character set strings and Unicode strings. "but I couldn't use it.

0


source







All Articles