Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ Builder 2009 vs. Delphi 2009: UnicodeString 2

Status
Not open for further replies.

BoMi

Programmer
Jul 20, 2006
39
RS
Hi!

Me again :)

Consider this piece of code:
Code:
   s: UnicodeString;
   
   s := '?? ?? ?? ?? ?? ?? ?? ????????????????????';

   Memo1.Lines.Add(s);

and the same lines in C++ Builder:
Code:
   UnicodeString s;
   
   s = "?? ?? ?? ?? ?? ?? ?? ????????????????????";

   Memo1->Lines->Add(s);

Now, during runtime, Delphi correctly displays that unicode string (which is Serbian Cyrillic), but C++ Builder not.

C++ Builder gives this warning, e.g.:

Code:
[BCC32 Warning] Unit1.cpp(19): W8114 Character represented by universal-character-name '\u0409' cannot be represented in the current code page (1250)
For other caracters too.

I'm not up to the speed to code page changing, I tried some stuff and it didn't work. Might figure it out later.

What I would like to know is: why in delphi that code works flawleslly and for C++ Builder to work I have to do some code page setting or whatever?
It should be the same principle.

Any ideas?

Best regards...
 
It may be that in C++, the memo component cannot handle Unicode. The first thing that comes to my mind is, 1) do you have all the updates installed (there are two that I know about), 2) cast the Unicode to an AnsiString and see what happens.



James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Thank you, 2ffat, for your response.

Actually the same happens with label, edit and richedit components, too. So, I guess, it's not up to the memo.

1) Will check for updates, but I think studio is updated.

2) Nothing happens, you get boxes and question marks instead of real letters, which is ok 'cause AnsiString simply can't show those symbols. The problem is I get question marks with UnicodeString, too.

It makes me really mad, sometimes, that Delphi always works better, have better support etc., while I'm stuck with C++ lately.

Anyway, I did a workaround of some sorts. I save all the text I'm using in my program to the unicode .txt file, put it in application's resource file and load it at the start of the application into the TStringList. Then those strings put where needed. That way it works flawleslly.

But, it's not what I hopped for in the first place.

Best regards...
 
I know this is somewhat a late response but I got here after a google search so I guess other people will end up here as well.

Even while your source file is Unicode, giving a string like

s = "?? ?? ?? ?? ?? ?? ?? ????????????????????";

makes the compiler interpret that string as AnsiString and tries to cast that to UnicodeString as ASCII, which, in your case will be in a code-page not containing eastern characters.
Backwards compatibility is the reason why he tries to convert it from ASCII and not UTF-8 (as your source file is).
You should prefix it with L :

s = L"?? ?? ?? ?? ?? ?? ?? ????????????????????";
 
Hi, theKris!

That worked!

So, I actually need to tell the compiler clearly that I want 2 bytes per character. What a b***s***!
I expected the Unicodestring to be a real unicodestring.
Anyway, in Delphi it works right.

Thank you very much for the solution, I would actually never think of that. I gave up trying to solve it because lack of time for that project and I won't change it now it's finished, but I'm very grateful for the peace you gave to my mind.

Best regards...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top