Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Delphi versions prior to Delphi 2009 <em>do</em> have Unicode support built in. The <strong><code>WideString</code></strong> type has been available since Delphi 4, I think, maybe earlier. <code>WideString</code> isn't as nice as the new <code>UnicodeString</code> type, but it still holds 16-bit Unicode characters, and you can type-cast it to <strong><code>PWideChar</code></strong> to send strings to Unicode API functions. The <code>Windows</code> unit declares most of the "wide" versions of the API functions, and there's nothing to stop you from declaring other functions yourself if you find some missing.</p> <p>What prior versions don't have is Unicode support in the VCL. For that, you can use the <strong>Tnt Unicode controls</strong>. They used to be free. Looks like there are a few places where the latest free version is still available: <a href="http://mh-nexus.de/en/tntunicodecontrols.php" rel="noreferrer">(1)</a>, <a href="http://www.yunqa.de/delphi/doku.php/products/tntunicodecontrols/index" rel="noreferrer">(2)</a>.</p> <p>The <a href="http://homepages.codegear.com/jedi/jcl/" rel="noreferrer"><strong>JCL</strong></a> has a couple of units for working with Unicode. The <strong><code>JclWideStrings</code></strong> unit has mostly light-weight utility functions. The <strong><code>JclUnicode</code></strong> unit is more complete, but it also includes a sizable resource for determining character properties of all Unicode characters.</p> <p>With the JCL you have a few choices for classes to hold lists of <code>WideString</code> values. I think Delphi 7 even comes with a class for that.</p> <p>Don't think that just because you don't have Delphi 2009 you can't write a Unicode program.</p> <p>If you have a <code>WideString</code> value, and you want to encode it as UTF-8, then call the <strong><code>Utf8Encode</code></strong> function. It will return an <code>AnsiString</code> value, or possibly <code>Utf8String</code>, if your Delphi version declares that type. It's not the same as Delphi 2009's <code>Utf8String</code> type, though. Delphi 2009's will <em>automatically</em> convert to <code>UnicodeString</code> or <code>AnsiString(x)</code> and vice versa in assignment statements. Prior versions just have a single <code>AnsiString</code> type, so you need to keep track for yourself which variables hold UTF-8 data and which hold Ansi data. (Hungarian notation on your variable and parameter names can help you keep track.) And of course, there's also a <strong><code>Utf8Decode</code></strong> function for converting UTF-8 data back to <code>WideString</code>.</p> <p>For handling other character encodings, you want to check out <a href="http://www.philo.de/xml/" rel="noreferrer"><strong>Open XML</strong></a>, a free XML library for Delphi. As part of its XML handling, it has support for converting between 70 different encodings.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload