Charset Delphi DLL Reference Documentation

Charset

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.

Create/Dispose

function CkCharset_Create: HCkCharset; stdcall;

Creates an instance of the HCkCharset object and returns a handle (i.e. a Pointer). The handle is passed in the 1st argument for the functions listed on this page.

procedure CkCharset_Dispose(handle: HCkCharset); stdcall;

Objects created by calling CkCharset_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.

Properties

procedure CkCharset_getAltToCharset(objHandle: HCkCharset; outPropVal: HCkString); stdcall;
procedure CkCharset_putAltToCharset(objHandle: HCkCharset; newPropVal: PWideChar); stdcall;

function CkCharset__altToCharset(objHandle: HCkCharset): PWideChar; stdcall;

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.

procedure CkCharset_getDebugLogFilePath(objHandle: HCkCharset; outPropVal: HCkString); stdcall;
procedure CkCharset_putDebugLogFilePath(objHandle: HCkCharset; newPropVal: PWideChar); stdcall;

function CkCharset__debugLogFilePath(objHandle: HCkCharset): PWideChar; stdcall;

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.

function CkCharset_getErrorAction(objHandle: HCkCharset): Integer; stdcall;
procedure CkCharset_putErrorAction(objHandle: HCkCharset; newPropVal: Integer); stdcall;

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.

procedure CkCharset_getFromCharset(objHandle: HCkCharset; outPropVal: HCkString); stdcall;
procedure CkCharset_putFromCharset(objHandle: HCkCharset; newPropVal: PWideChar); stdcall;

function CkCharset__fromCharset(objHandle: HCkCharset): PWideChar; stdcall;

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


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

procedure CkCharset_getLastErrorHtml(objHandle: HCkCharset; outPropVal: HCkString); stdcall;

function CkCharset__lastErrorHtml(objHandle: HCkCharset): PWideChar; stdcall;

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.

procedure CkCharset_getLastErrorText(objHandle: HCkCharset; outPropVal: HCkString); stdcall;

function CkCharset__lastErrorText(objHandle: HCkCharset): PWideChar; stdcall;

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.

Concept of LastErrorText

LastErrorText Standard Information

procedure CkCharset_getLastErrorXml(objHandle: HCkCharset; outPropVal: HCkString); stdcall;

function CkCharset__lastErrorXml(objHandle: HCkCharset): PWideChar; stdcall;

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.

procedure CkCharset_getLastInputAsHex(objHandle: HCkCharset; outPropVal: HCkString); stdcall;

function CkCharset__lastInputAsHex(objHandle: HCkCharset): PWideChar; stdcall;

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.

procedure CkCharset_getLastInputAsQP(objHandle: HCkCharset; outPropVal: HCkString); stdcall;

function CkCharset__lastInputAsQP(objHandle: HCkCharset): PWideChar; stdcall;

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.

function CkCharset_getLastMethodSuccess(objHandle: HCkCharset): wordbool; stdcall;
procedure CkCharset_putLastMethodSuccess(objHandle: HCkCharset; newPropVal: wordbool); stdcall;

Introduced in version 9.5.0.52

Indicate whether the last method call succeeded or failed. A value of True indicates success, a value of False 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 = True and failure = False.
  • 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 True. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

procedure CkCharset_getLastOutputAsHex(objHandle: HCkCharset; outPropVal: HCkString); stdcall;

function CkCharset__lastOutputAsHex(objHandle: HCkCharset): PWideChar; stdcall;

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.

procedure CkCharset_getLastOutputAsQP(objHandle: HCkCharset; outPropVal: HCkString); stdcall;

function CkCharset__lastOutputAsQP(objHandle: HCkCharset): PWideChar; stdcall;

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.

function CkCharset_getSaveLast(objHandle: HCkCharset): wordbool; stdcall;
procedure CkCharset_putSaveLast(objHandle: HCkCharset; newPropVal: wordbool); stdcall;

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)

procedure CkCharset_getToCharset(objHandle: HCkCharset; outPropVal: HCkString); stdcall;
procedure CkCharset_putToCharset(objHandle: HCkCharset; newPropVal: PWideChar); stdcall;

function CkCharset__toCharset(objHandle: HCkCharset): PWideChar; stdcall;

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


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

function CkCharset_getVerboseLogging(objHandle: HCkCharset): wordbool; stdcall;
procedure CkCharset_putVerboseLogging(objHandle: HCkCharset; newPropVal: wordbool); stdcall;

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

procedure CkCharset_getVersion(objHandle: HCkCharset; outPropVal: HCkString); stdcall;

function CkCharset__version(objHandle: HCkCharset): PWideChar; stdcall;

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

Methods

function CkCharset_CharsetToCodePage(objHandle: HCkCharset;
    charsetName: PWideChar): Integer; stdcall;

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

function CkCharset_CodePageToCharset(objHandle: HCkCharset;
    codePage: Integer;
    outCharset: HCkString): wordbool; stdcall;

function CkCharset__codePageToCharset(objHandle: HCkCharset;
    codePage: Integer): PWideChar; stdcall;

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

Returns True for success, False for failure.

function CkCharset_ConvertData(objHandle: HCkCharset;
    inData: HCkByteData;
    outData: HCkByteData): wordbool; stdcall;

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 True for success, False for failure.

function CkCharset_ConvertFile(objHandle: HCkCharset;
    inPath: PWideChar;
    destPath: PWideChar): wordbool; stdcall;

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 True for success, False for failure.

function CkCharset_ConvertFileNoPreamble(objHandle: HCkCharset;
    inPath: PWideChar;
    destPath: PWideChar): wordbool; stdcall;

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.

function CkCharset_ConvertFromUnicode(objHandle: HCkCharset;
    inData: PWideChar;
    outBytes: HCkByteData): wordbool; stdcall;

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

Returns True for success, False for failure.

function CkCharset_ConvertFromUtf16(objHandle: HCkCharset;
    uniData: HCkByteData;
    outMbData: HCkByteData): wordbool; stdcall;

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

Returns True for success, False for failure.

function CkCharset_ConvertHtml(objHandle: HCkCharset;
    inData: HCkByteData;
    outHtml: HCkByteData): wordbool; stdcall;

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 True for success, False for failure.

function CkCharset_ConvertHtmlFile(objHandle: HCkCharset;
    inPath: PWideChar;
    destPath: PWideChar): wordbool; stdcall;

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 True for success, False for failure.

function CkCharset_ConvertToUnicode(objHandle: HCkCharset;
    inData: HCkByteData;
    outStr: HCkString): wordbool; stdcall;

function CkCharset__convertToUnicode(objHandle: HCkCharset;
    inData: HCkByteData): PWideChar; stdcall;

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

Returns True for success, False for failure.

function CkCharset_ConvertToUtf16(objHandle: HCkCharset;
    mbData: HCkByteData;
    outUniData: HCkByteData): wordbool; stdcall;

To be documented soon.

Returns True for success, False for failure.

function CkCharset_EntityEncodeDec(objHandle: HCkCharset;
    str: PWideChar;
    outStr: HCkString): wordbool; stdcall;

function CkCharset__entityEncodeDec(objHandle: HCkCharset;
    str: PWideChar): PWideChar; stdcall;

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

Returns True for success, False for failure.

function CkCharset_EntityEncodeHex(objHandle: HCkCharset;
    str: PWideChar;
    outStr: HCkString): wordbool; stdcall;

function CkCharset__entityEncodeHex(objHandle: HCkCharset;
    str: PWideChar): PWideChar; stdcall;

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

Returns True for success, False for failure.

function CkCharset_GetHtmlCharset(objHandle: HCkCharset;
    inData: HCkByteData;
    outCharset: HCkString): wordbool; stdcall;

function CkCharset__getHtmlCharset(objHandle: HCkCharset;
    inData: HCkByteData): PWideChar; stdcall;

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

Returns True for success, False for failure.

function CkCharset_GetHtmlFileCharset(objHandle: HCkCharset;
    htmlFilePath: PWideChar;
    outCharset: HCkString): wordbool; stdcall;

function CkCharset__getHtmlFileCharset(objHandle: HCkCharset;
    htmlFilePath: PWideChar): PWideChar; stdcall;

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

Returns True for success, False for failure.

function CkCharset_HtmlDecodeToStr(objHandle: HCkCharset;
    inStr: PWideChar;
    outStr: HCkString): wordbool; stdcall;

function CkCharset__htmlDecodeToStr(objHandle: HCkCharset;
    inStr: PWideChar): PWideChar; stdcall;

Converts HTML entities to Unicode characters.

Returns True for success, False for failure.

function CkCharset_HtmlEntityDecode(objHandle: HCkCharset;
    inHtml: HCkByteData;
    outData: HCkByteData): wordbool; stdcall;

Decodes HTML entities. See http://www.w3.org/TR/REC-html40/sgml/entities.html for information on HTML entities. Examples of HTML entities are < , å , å , 水 , Í , etc.

Returns True for success, False for failure.

function CkCharset_HtmlEntityDecodeFile(objHandle: HCkCharset;
    inPath: PWideChar;
    destPath: PWideChar): wordbool; stdcall;

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 < , å , å , 水 , Í , etc.

Returns True for success, False for failure.

function CkCharset_IsUnlocked(objHandle: HCkCharset): wordbool; stdcall;

Returns true if the component is unlocked.

function CkCharset_LowerCase(objHandle: HCkCharset;
    inStr: PWideChar;
    outStr: HCkString): wordbool; stdcall;

function CkCharset__lowerCase(objHandle: HCkCharset;
    inStr: PWideChar): PWideChar; stdcall;

Converts a string to lowercase.

Returns True for success, False for failure.

function CkCharset_ReadFile(objHandle: HCkCharset;
    path: PWideChar;
    outData: HCkByteData): wordbool; stdcall;

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

Returns True for success, False for failure.

function CkCharset_ReadFileToString(objHandle: HCkCharset;
    path: PWideChar;
    charset: PWideChar;
    outStr: HCkString): wordbool; stdcall;

function CkCharset__readFileToString(objHandle: HCkCharset;
    path: PWideChar;
    charset: PWideChar): PWideChar; stdcall;

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 True for success, False for failure.

function CkCharset_SaveLastError(objHandle: HCkCharset;
    path: PWideChar): wordbool; stdcall;

Saves the last-error information (the contents of LastErrorXml) to an XML formatted file.

Returns True for success, False for failure.

procedure CkCharset_SetErrorBytes(objHandle: HCkCharset;
    data: HCkByteData) stdcall;

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.

procedure CkCharset_SetErrorString(objHandle: HCkCharset;
    str: PWideChar;
    charset: PWideChar) stdcall;

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.

function CkCharset_UnlockComponent(objHandle: HCkCharset;
    unlockCode: PWideChar): wordbool; stdcall;

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 True for success, False for failure.

Diagnosing UnlockComponent Problems

UnlockComponent LastErrorText shows exact string passed to it.

Verify UnlockComponent Success w/ Permanent Unlock Code

LastErrorText Standard Information

function CkCharset_UpperCase(objHandle: HCkCharset;
    inStr: PWideChar;
    outStr: HCkString): wordbool; stdcall;

function CkCharset__upperCase(objHandle: HCkCharset;
    inStr: PWideChar): PWideChar; stdcall;

Converts a string to uppercase.

Returns True for success, False for failure.

function CkCharset_UrlDecodeStr(objHandle: HCkCharset;
    inStr: PWideChar;
    outStr: HCkString): wordbool; stdcall;

function CkCharset__urlDecodeStr(objHandle: HCkCharset;
    inStr: PWideChar): PWideChar; stdcall;

URL decodes a string.

Returns True for success, False for failure.

function CkCharset_VerifyData(objHandle: HCkCharset;
    charset: PWideChar;
    inData: HCkByteData): wordbool; stdcall;

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

function CkCharset_VerifyFile(objHandle: HCkCharset;
    charset: PWideChar;
    path: PWideChar): wordbool; stdcall;

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

function CkCharset_WriteFile(objHandle: HCkCharset;
    path: PWideChar;
    byteData: HCkByteData): wordbool; stdcall;

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

function CkCharset_WriteStringToFile(objHandle: HCkCharset;
    textData: PWideChar;
    path: PWideChar;
    charset: PWideChar): wordbool; stdcall;

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 True for success, False for failure.