TChilkatCharset Delphi ActiveX Reference Documentation

TChilkatCharset

Current Version: 9.5.0.98

A component/class for converting character data from one encoding to another. This software is unique in that the data required for converting to/from the supported charsets is entirely embedded witin the Chilkat DLL/library. It does not depend on what code pages may or may not be installed on a particular computer. This allows programs to operate correctly regardless of the locale, OS version, or other factors.

Importing the Chilkat ActiveX into Delphi

Important: When upgrading to a new version of Chilkat, make sure to re-imported ActiveX DLL into Delphi to regenerate the files described below.

Two things are required to use an ActiveX in Delphi:

  1. The ActiveX DLL needs to be registered via regsvr32 on the system where the Delphi application runs. See How To Register ActiveX DLLs for detailed information.
  2. See also: ActiveX Registration Tutorial
  3. The ActiveX component needs to be "imported". Use the Delphi Import Component Wizard to import the Chilkat type library. This creates the following files: Chilkat_v9_5_0_TLB.pas and Chilkat_v9_5_0_TLB.dcr. The Chilkat_v9_5_0_TLB.pas should be added to your project.

To import the Chilkat type library, do the following:

  1. In the Delphi RAD Studio, select the menu item "Component" --> "Import a Type Library".
  2. Find "Chilkat ActiveX v9.5.0" in the list and select it. This will only appear in the list if the ChilkatAx-9.5.0-win32.dll (or ChilkatAx-9.5.0-x64.dll) has been registered w/ regsvr32.
  3. Check the "Generate Component Wrappers" checkbox.
  4. Select a directory where the unit files (.pas and .dcr) should be generated.
  5. Select "Create Unit" and then "Finish".
  6. Add the .pas to your Delphi project.

To use a Chilkat ActiveX object in your Delphi code, add "Chilkat_v9_5_0_TLB" to the "uses" statement. For example:

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_v9_5_0_TLB;

Object Creation

var
obj: TChilkatCharset;
...
begin
obj := TChilkatCharset.Create(Self);
...
// When finished, free the object instance.
obj.Free();

Properties

AltToCharset
property AltToCharset: WideString

If the ErrorAction property is set to 6, then this property controls how errors are handled. It specifies an alternate "To" charset. When a character in the input data cannot be converted to the target charset, an attempt is made to convert it to the AltToCharset. If that fails, the input character is dropped.

top
DebugLogFilePath
property DebugLogFilePath: WideString

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

More Information and Examples
top
ErrorAction
property ErrorAction: Integer

Controls how errors are handled. When a character in the input data cannot be converted to the target charset, the action taken is controlled by this property. The possible settings are: (0) drop the error characters, (1) substitute the data set by the SetErrorBytes or SetErrorString method, (2) convert to a hex-escaped string (&#xXXXX), (3) RESERVED, (4) RESERVED, (5) RESERVED, (6) convert the error character to the AltToCharset instead, if that fails then drop the character, (7) Pass non-convertible characters to the output unchanged.

top
FromCharset
property FromCharset: WideString

Tells the charset converter the charset of the input data for a conversion. Possible values are:

<font size="2" face="MS Sans Serif">
us-ascii
unicode  (also known as UTF16LE or simply UTF16)
unicodefffe  (also known as UTF16BE)
ebcdic
iso-8859-1
iso-8859-2
iso-8859-3
iso-8859-4
iso-8859-5
iso-8859-6
iso-8859-7
iso-8859-8
iso-8859-9
iso-8859-13
iso-8859-15
windows-874
windows-1250
windows-1251
windows-1252
windows-1253
windows-1254
windows-1255
windows-1256
windows-1257
windows-1258
utf-7
utf-8
utf-32
utf-32be
shift_jis
gb2312
ks_c_5601-1987
big5
iso-2022-jp
iso-2022-kr
euc-jp
euc-kr
macintosh
x-mac-japanese
x-mac-chinesetrad
x-mac-korean
x-mac-arabic
x-mac-hebrew
x-mac-greek
x-mac-cyrillic
x-mac-chinesesimp
x-mac-romanian
x-mac-ukrainian
x-mac-thai
x-mac-ce
x-mac-icelandic
x-mac-turkish
x-mac-croatian
asmo-708
dos-720
dos-862
ibm01140
ibm01141
ibm01142
ibm01143
ibm01144
ibm01145
ibm01146
ibm01147
ibm01148
ibm01149
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u
</font>

top
LastBinaryResult
property LastBinaryResult: OleVariant readonly

The binary data returned by the last (binary data returning) method called. Only available if Chilkat.Global.KeepBinaryResult is set to 1. This provides a means for obtaining large varbinary results in the SQL Server environment (where limitations exist in getting large amounts of data returned by method calls, but where temp tables can be used for binary properties).

top
LastErrorHtml
property LastErrorHtml: WideString readonly

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastErrorText
property LastErrorText: WideString readonly

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastErrorXml
property LastErrorXml: WideString readonly

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastInputAsHex
property LastInputAsHex: WideString readonly

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last input data in a hexidecimalized string.

top
LastInputAsQP
property LastInputAsQP: WideString readonly

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last input data in a quoted-printable string.

top
LastMethodSuccess
property LastMethodSuccess: Integer

Indicate whether the last method call succeeded or failed. A value of 1 indicates success, a value of 0 indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = 1 and failure = 0.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to 1. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

top
LastOutputAsHex
property LastOutputAsHex: WideString readonly

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last output data in a hexidecimalized string.

top
LastOutputAsQP
property LastOutputAsQP: WideString readonly

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last output data in a quoted-printable string.

top
LastStringResult
property LastStringResult: WideString readonly

The string return value of the last (string returning) method called. Only available if Chilkat.Global.KeepStringResult is set to 1. This provides a means for obtaining large string results in the SQL Server environment (where limitations exist in getting long strings returned by method calls, but where temp tables can be used for string properties).

top
LastStringResultLen
property LastStringResultLen: Integer readonly

The length, in characters, of the string contained in the LastStringResult property.

top
SaveLast
property SaveLast: Integer

Tells the component to keep the input/output byte data in memory after a conversion is complete so the data can be examined via the LastInputAsHex/QP and LastOutputAsHex/QP properties. (for debugging purposes)

top
ToCharset
property ToCharset: WideString

Tells the charset converter the target charset for a conversion. Possible values are:

<font size="2" face="MS Sans Serif">
us-ascii
unicode  (also known as UTF16LE or simply UTF16)
unicodefffe  (also known as UTF16BE)
ebcdic
iso-8859-1
iso-8859-2
iso-8859-3
iso-8859-4
iso-8859-5
iso-8859-6
iso-8859-7
iso-8859-8
iso-8859-9
iso-8859-13
iso-8859-15
windows-874
windows-1250
windows-1251
windows-1252
windows-1253
windows-1254
windows-1255
windows-1256
windows-1257
windows-1258
utf-7
utf-8
utf-32
utf-32be
shift_jis
gb2312
ks_c_5601-1987
big5
iso-2022-jp
iso-2022-kr
euc-jp
euc-kr
macintosh
x-mac-japanese
x-mac-chinesetrad
x-mac-korean
x-mac-arabic
x-mac-hebrew
x-mac-greek
x-mac-cyrillic
x-mac-chinesesimp
x-mac-romanian
x-mac-ukrainian
x-mac-thai
x-mac-ce
x-mac-icelandic
x-mac-turkish
x-mac-croatian
asmo-708
dos-720
dos-862
ibm01140
ibm01141
ibm01142
ibm01143
ibm01144
ibm01145
ibm01146
ibm01147
ibm01148
ibm01149
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u
</font>

top
VerboseLogging
property VerboseLogging: Integer

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
property Version: WideString readonly

Version of the component/library, such as "9.5.0.94"

More Information and Examples
top

Methods

CharsetToCodePage
function CharsetToCodePage(charsetName: WideString): Integer;

Converts a charset name to a code page number. For example, "iso-8859-1" converts to code page 28591.

top
CodePageToCharset
function CodePageToCharset(codePage: Integer): WideString;

Converts a code page number to a charset name. For example, 65001 converts to "utf-8".

Returns a zero-length WideString on failure

top
ConvertData
function ConvertData(inData: OleVariant): OleVariant;

Converts character data from one charset to another. Before calling ConvertData, the FromCharset and ToCharset properties must be set to the source and destination charset names, such as "iso-8859-1" or "Shift_JIS".

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

top
ConvertFile
function ConvertFile(inPath: WideString; destPath: WideString): Integer;

Converts a file from one character encoding to another. The FromCharset and ToCharset properties specify the source and destination character encodings. If the ToCharset is utf-16 or utf-8, then the preamble (also known as BOM) is included in the output. (Call ConvertFileNoPreamble to suppress the output of the BOM.)

Returns 1 for success, 0 for failure.

top
ConvertFileNoPreamble
function ConvertFileNoPreamble(inPath: WideString; destPath: WideString): Integer;

Converts a file from one character encoding to another. The FromCharset and ToCharset properties specify the source and destination character encodings. No preamble (also known as BOM) is included in the output.

top
ConvertFromUnicode
function ConvertFromUnicode(inData: WideString): OleVariant;

Converts Unicode (utf-16) text to the charset specified by the ToCharset property.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

top
ConvertFromUtf16
function ConvertFromUtf16(uniData: OleVariant): OleVariant;

Converts utf-16 text to the charset specified by the ToCharset property.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

top
ConvertHtml
function ConvertHtml(inData: OleVariant): OleVariant;

Converts HTML text from one character encoding to another. The FromCharset and ToCharset properties must be set prior to calling this method. This method automatically edits the META tag within the HTML that indicates the charset.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

top
ConvertHtmlFile
function ConvertHtmlFile(inPath: WideString; destPath: WideString): Integer;

Converts an HTML file from one character encoding to another. The ToCharset properties must be set prior to calling this method. If the FromCharset is not set, it is obtained from the HTML META tag that indicates the charset. This method automatically edits the META tag within the HTML that indicates the charset.

Returns 1 for success, 0 for failure.

top
ConvertToUnicode
function ConvertToUnicode(inData: OleVariant): WideString;

Converts multibyte character data to a Unicode string. The FromCharset property should be set before calling this method.

Returns a zero-length WideString on failure

top
ConvertToUtf16
function ConvertToUtf16(mbData: OleVariant): OleVariant;

Converts the mbData to utf-16 bytes.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

top
EntityEncodeDec
function EntityEncodeDec(str: WideString): WideString;

Converts non-US-ASCII characters to Unicode decimal entities (&#xxxxx;)

Returns a zero-length WideString on failure

top
EntityEncodeHex
function EntityEncodeHex(str: WideString): WideString;

Converts non-US-ASCII characters to Unicode hex entities (&#xXXXX;)

Returns a zero-length WideString on failure

top
GetHtmlCharset
function GetHtmlCharset(inData: OleVariant): WideString;

Examines HTML text and extracts the charset name specified by the META tag, if present.

Returns a zero-length WideString on failure

top
GetHtmlFileCharset
function GetHtmlFileCharset(htmlFilePath: WideString): WideString;

Examines an HTML file and extracts the charset name specified by the META tag, if present.

Returns a zero-length WideString on failure

top
HtmlDecodeToStr
function HtmlDecodeToStr(inStr: WideString): WideString;

Converts HTML entities to Unicode characters.

Returns a zero-length WideString on failure

top
HtmlEntityDecode
function HtmlEntityDecode(inHtml: OleVariant): OleVariant;

Decodes HTML entities. See http://www.w3.org/TR/REC-html40/sgml/entities.html for information on HTML entities. Examples of HTML entities are &lt; , &#229; , &#xE5; , &#x6C34; , &Iacute; , etc.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

top
HtmlEntityDecodeFile
function HtmlEntityDecodeFile(inPath: WideString; destPath: WideString): Integer;

Decodes HTML entities in a file and creates a new HTML file with the entities decoded. See http://www.w3.org/TR/REC-html40/sgml/entities.html for information on HTML entities. Examples of HTML entities are &lt; , &#229; , &#xE5; , &#x6C34; , &Iacute; , etc.

Returns 1 for success, 0 for failure.

top
LowerCase
function LowerCase(inStr: WideString): WideString;

Converts a string to lowercase.

Returns a zero-length WideString on failure

top
ReadFile
function ReadFile(path: WideString): OleVariant;

Convenience method for reading the entire contents of a file into a byte array.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

top
ReadFileToString
function ReadFileToString(path: WideString; charset: WideString): WideString;

Reads a text file and returns the text converted to a Unicode string. The filename is specified by the first method argument, and the charset of the text data is specified by the 2nd method argument.

Returns a zero-length WideString on failure

top
SetErrorBytes
procedure SetErrorBytes(data: OleVariant);

If the ErrorAction property is set to 1, the bytes passed to this method are used as the result for any characters that cannot be converted during a conversion.

top
SetErrorString
procedure SetErrorString(str: WideString; charset: WideString);

If the ErrorAction property is set to 1, the string passed to this method is used as the result for any characters that cannot be converted during a conversion.

top
UnlockComponent
function UnlockComponent(unlockCode: WideString): Integer;

Unlocks the component. This method must be called once at the beginning of the program. Properties can be get/set without unlocking, but methods will not work unless the component has been unlocked.

Returns 1 for success, 0 for failure.

top
UpperCase
function UpperCase(inStr: WideString): WideString;

Converts a string to uppercase.

Returns a zero-length WideString on failure

top
UrlDecodeStr
function UrlDecodeStr(inStr: WideString): WideString;

URL decodes a string.

This method assumes the ANSI byte representation was used for encoding. For example, the letter É, where the ANSI charset is Latin-1, would appear as "%C9" when URL encoded. (As opposed to the utf-8 encoding where É is represented by 2 bytes 0xC3, 0x89 and would appear as "%C3%89" when URl encoded. This method assumes ANSI encoding.

You can use encoding/decoding methods in Chilkat's StringBuilder class to specify the charset from which to decode or encode.

Returns a zero-length WideString on failure

top
VerifyData
function VerifyData(charset: WideString; inData: OleVariant): Integer;

Returns true if the byte data conforms to the charset passed in the first argument.

top
VerifyFile
function VerifyFile(charset: WideString; path: WideString): Integer;

Returns true if the file contains character data that conforms to the charset passed in the 1st argument.

top
WriteFile
function WriteFile(path: WideString; byteData: OleVariant): Integer;

Convenience method for saving an entire byte array to a file.

top
WriteStringToFile
function WriteStringToFile(textData: WideString; path: WideString; charset: WideString): Integer;

Converts a Unicode string to a multibyte charset and writes the multibyte text data to a file. The destination charset is specified in the 2nd method argument.

Returns 1 for success, 0 for failure.

top