A customer is having trouble converting Shift_JIS to Unicode and displaying it in a Delphi program — and so am I. Well, the conversion is easy, it’s just the display part that is seemingly impossible. Here’s a reference: http://homepages.borland.com/efg2lab/OtherProjects/Unicode.htm
"Delphi supports Unicode characters and strings through the WideChar, pWideChar, and WideString types.
In Delphi you can access WideChars (since they are accessible from the Windows API) but you cannot display Unicode strings in native Delphi controls (at this time). "
I wrote this example program to demonstrate (you’ll get question marks for the Japanese characters in the Memo). PS> Make sure to download the latest Chilkat Charset ActiveX from http://www.chilkatsoft.com/download/CharsetActiveX.msi because you’ll need to import the ChilkatUtil.dll which is used as a helper.
Here’s the code:
procedure TForm1.Button1Click(Sender: TObject);
// Load a Shift-JIS encoded HTML file. This is an HTML page saved from yomiuri.com — a Japanese online newspaper that uses the Shift_JIS encoding.
ChilkatCharset21.FromCharset := ‘Shift_JIS’;
ChilkatCharset21.ToCharset := ‘Unicode’;
// Uncomment this if you wish to view the LastInput/Output properties.
ChilkatCharset21.SaveLast := 1;
// This converts the Shift_JIS byte data to a Unicode WideString.
str := ChilkatCharset21.ConvertToUnicode(CkData1.GetBinary());
// Display Unicode???
// Displaying Japanese text in Delphi is something I don’t know how to do…
// You will probably see question marks for the Japanese characters.
Memo1.Text := str;
//Memo1.Text := ChilkatCharset21.LastOutputAsQP;
// Verify that the string was correctly converted by saving the WideString
// to a file.
// NOTE: Use an editor such as Emurasoft’s EM-Editor to view text files
// in any character encoding. You can verify that it is Unicode by
// doing a "Save-As" in EM-Editor and you will see that Unicode is the
// selected character encoding.