views:

1492

answers:

7

Hi guys, I have a little trouble with RAD Studio 2009.
As you know, it is possible to switch Unicode support off in MSVS (right click on solution->properties->character set=not set). I need to find this feature in RAD Studio, I know it exists but do not know where exactly.
It`s the only thing that stops my work on a Socket Chat university project.
P.S. The problem appeared after I have installed the update from CodeGear official site.

A: 

I`ve solved the problem this way:


    wchar_t* str = Form2->Edit1->Text.w_str();
    char* mystr = new char [Form2->Edit1->Text.Length() + 1];
    WideCharToMultiByte(CP_ACP, 0, str, -1, mystr, Form2->Edit1->Text.Length() + 1, NULL, NULL);
    MessageBox(NULL, mystr, "It`s ok", MB_OK);
    delete []mystr;

but it seems to me that there`s another way

chester89
+11  A: 

Short answer: No, there is no such feature to turn off Unicode in RAD Studio 2009.

Craig Stuntz
+1  A: 

Is it possible to turn off it? The better question is: should you turn it off? And the answer is: NO.

It's far to design the application so that Unicode characters are sent properly when serialized (for example, in sockets in your application), than to design a non-Unicode program in a Unicode world. Even for a simple project, it's worth learning Unicode in principle.

+1  A: 

To be precise, you can get your C++ Builder application to be built without the #UNICODE flag being defined by modifying the project options for "TCHAR maps to char".

This means that SendMessage will call SendMessageA, etc, and the TCHAR

However, if you're using any VCL functions, there are no non-unicode equivalents to those. The VCL is now inherrently Unicode, and that can NOT be changed.

Re: your "solution"- there's an easier way. which works with both TCHAR = char or wchar_t:

MessageBox(NULL, Form2->Edit1->Text.t_str(), _TEXT("It`s ok"), MB_OK);
Roddy
Usage of the _TEXT macros and so forth would be something to use there, so if the move to Unicode is made, it won't be as horrendous for explicit strings.
Kris Kumler
You're right. Thanks.
Roddy
+3  A: 

You have to be careful using the UnicodeString::t_str() method. If you call it in a project that is compiled for Ansi rather than Unicode, t_str() alters the internal contents of the UnicodeString. That can have unexpected side effects, especially for UnicodeString values that come from controls.

Remy Lebeau - TeamB
Remy, it's great to see you here! Welcome to StackOverflow. The Delphi community here just got a whole lot richer!
Argalatyr
+3  A: 

chester - You don't need to call WideCharToMultiByte() directly. Let the RTL do the work for you:

AnsiString s = Form2->Edit1->Text;
MessageBoxA(NULL, s.c_str(), "It`s ok", MB_OK);
Remy Lebeau - TeamB
A: 

There is a better way, I do it like this:

MessageBox(NULL, Form2->Edit1->Text.w_str(), L"It`s ok", MB_OK);
Gary Benade