Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

October 7, 2005

Delphi and Unicode

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:

An excerpt:
"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 because you’ll need to import the ChilkatUtil.dll which is used as a helper.

Here’s the code:

procedure TForm1.Button1Click(Sender: TObject);
str: WideString;
// Load a Shift-JIS encoded HTML file. This is an HTML page saved from — 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.


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.