Board index » delphi » MBCS and TEdit

MBCS and TEdit


2003-07-23 03:34:05 PM
delphi74
Hello!
First of all I have the following question: Is UTF-8 = MBCS? Or at least: Is
UTF-8 a kind of MBCS?
I'm not able to show MBCS strings with TEdit: I use {$H+}, so Delphi should
interpret strings of type "string" as MBCS, right?
Now I try to assign to a TEdit a UTF-8 string (EdVCL is a ordinary TEdit):
EdVCL.Text := UTF8String(#$C4#$85#$C5#$82#$C4#$99#$C5#$9B);
The string I assign should contain 4 polish characters ("special" a, l, e,
s), but the TEdit shows 8 strange characters instead of the 4 polish
characters. If I use a TTnTEdit (a component which can show UNICODE
characters) and assign the same string (first converted into Unicode):
EdTnT.Text := UTF8Decode(UTF8String(#$C4#$85#$C5#$82#$C4#$99#$C5#$9B));
The EdTnT component shows the correct 4 polish characters. What am I doing
wrong?
It would be great if someone could show me an example how to display MBCS
with TEdit
Thanks,
Alexander
 
 

Re:MBCS and TEdit

In article <3f1e3a6e$XXXX@XXXXX.COM>, Alexander Corradini writes:
Quote
First of all I have the following question: Is UTF-8 = MBCS?
No.
Quote
Or at least: Is UTF-8 a kind of MBCS?
Yes. Like the WIndows MBCS system UTF-8 uses special prefix bytes to identify
characters that need to be encoded in more than one byte, but they are
different. For 7-bit ANSI characters the encoding is identical in UTF-8 and
ANSI, for others it is not.
Quote
I'm not able to show MBCS strings with TEdit: I use {$H+}, so Delphi should
interpret strings of type "string" as MBCS, right?
Delphi does no interpretation one way or the other, it is the Windows control
itself that does it. To display a MBCS string you need to set the edits Font
to a font that contains the proper encoding.
Quote
Now I try to assign to a TEdit a UTF-8 string (EdVCL is a ordinary TEdit):

EdVCL.Text := UTF8String(#$C4#$85#$C5#$82#$C4#$99#$C5#$9B);

The string I assign should contain 4 polish characters ("special" a, l, e,
s), but the TEdit shows 8 strange characters instead of the 4 polish
characters. If I use a TTnTEdit (a component which can show UNICODE
characters) and assign the same string (first converted into Unicode):

EdTnT.Text := UTF8Decode(UTF8String(#$C4#$85#$C5#$82#$C4#$99#$C5#$9B));

The EdTnT component shows the correct 4 polish characters. What am I doing
wrong?
You are barking up the wrong tree <g>. This is not a MBCS vs ANSI issue, it is
a CHARSET issue. Polish (like other European languages that need characters
not contained in the 7bit ANSI range) uses fonts with a different CHARSET
value (a different encoding for characters in the range #128..#255). But the
characters themselves are in that region, they are not encoded as MBCS. So
you use a normal Ansistring to hold the text. To display it correctly the edit
control needs a Font with the Charset property set to EASTEUROPE_CHARSET.
The standard system fonts (like Arial or Times New Roman) will have the proper
character glyphs *if* one of the east european locales has been installed on
the system.
Peter Below (TeamB)
Use the newsgroup archives :
www.mers.com/searchsite.html
www.tamaracka.com/search.htm
groups.google.com
www.prolix.be
 

Re:MBCS and TEdit

Hello Peter,
thank you very much for the information. Now the situation is much more
clear ;-)
I changed the Charset of the Font to "Easteurope_Charset" and it works fine.
Alexander