chester89
chester89

Reputation: 8627

Is it possible to turn off Unicode support in RAD Studio 2009?

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.

Upvotes: 2

Views: 4719

Answers (7)

Gary Benade
Gary Benade

Reputation: 507

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

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

Upvotes: 1

Remy Lebeau
Remy Lebeau

Reputation: 595837

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);

Upvotes: 4

Remy Lebeau
Remy Lebeau

Reputation: 595837

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.

Upvotes: 3

Roddy
Roddy

Reputation: 68033

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);

Upvotes: 1

asdffdsa
asdffdsa

Reputation:

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.

Upvotes: 1

Craig Stuntz
Craig Stuntz

Reputation: 126547

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

Upvotes: 12

chester89
chester89

Reputation: 8627

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

Upvotes: 0

Related Questions