Declaration¶
Source position: sysencodingh.inc line 27
type
TEncoding = class
public
function Clone : TEncoding;
class function Convert(Source: TEncoding; Destination: TEncoding;
const Bytes: TBytes) : TBytes; overload;
class function Convert(Source: TEncoding; Destination: TEncoding;
const Bytes: TBytes; StartIndex: Integer;
Count: Integer) : TBytes; overload;
class function IsStandardEncoding : Boolean;
class function GetBufferEncoding(const Buffer: TBytes;
var AEncoding: TEncoding) : Integer; overload;
class function GetBufferEncoding(const Buffer: TBytes;
var AEncoding: TEncoding;
ADefaultEncoding: TEncoding) : Integer; overload;
class function GetEncoding(CodePage: Integer) : TEncoding; overload;
class function GetEncoding(const EncodingName: UnicodeString)
: TEncoding; overload;
function GetMaxByteCount : Integer;
function GetMaxCharCount : Integer;
function GetPreamble : TBytes;
function GetString(const Bytes: TBytes) : UnicodeString; overload;
function GetString(const Bytes: TBytes; ByteIndex: Integer;
ByteCount: Integer) : UnicodeString; overload;
property CodePage: Cardinal; {r}
property EncodingName: UnicodeString; {r}
property IsSingleByte: Boolean; {r}
class property ANSI: TEncoding; {r}
class property ASCII: TEncoding; {r}
class property BigEndianUnicode: TEncoding; {r}
class property Default: TEncoding; {r}
class property SystemEncoding: TEncoding; {r}
class property Unicode: TEncoding; {r}
class property UTF7: TEncoding; {r}
class property UTF8: TEncoding; {r}
end;
Description¶
TEncoding is a mostly abstract class that contains various methods to deal with different encodings in single- and double-byte strings. In practice, one instance of a descendent of this class for each needed encoding can be instantiated and used. The class contains several class methods and properties to create such instances, and has several often-used instances available as class properties, in particular the default encoding.
When using encodings (and in particular TEncoding.Default or TEncoding.ANSI), if the DefaultSystemCodePage changes, you should call TEncoding.FreeEncodings to regenerate the encodings.
Properties¶
| Member | Visibility | Description |
|---|---|---|
| ANSI read only | public | Ansi encoding instance. |
| ASCII read only | public | ASCII encoding instance. |
| BigEndianUnicode read only | public | Big-endian Unicode (UTF16BE) encoding instance. |
| CodePage read only | public | Codepage for this encoding. |
| Default read only | public | Default codepage. |
| EncodingName read only | public | Name of this encoding. |
| IsSingleByte read only | public | Is the encoding a single-byte encoding or not ? |
| SystemEncoding read only | public | System encoding. |
| Unicode read only | public | UTF16 encoding instance. |
| UTF7 read only | public | UTF7 encoding instance. |
| UTF8 read only | public | UTF8 encoding instance. |
Methods¶
| Member | Visibility | Description |
|---|---|---|
| Clone | public | Clone a TEncoding instance. |
| Convert | public | Convert an array of bytes from one encoding to another. |
| GetBufferEncoding | public | Attempt to guess the encoding of a buffer. |
| GetEncoding | public | Get an encoding instance for a given codepage. |
| GetMaxByteCount | public | Returns the maximum number of bytes needed to represent a string. |
| GetMaxCharCount | public | Return the maximum number of characters that can be represented in a number of bytes. |
| GetPreamble | public | Return the BOM Marker used by the encoding. |
| GetString | public | Return a string based on an array of bytes. |
| IsStandardEncoding | public | Check if the encoding is one of the standard encodings. |
See also¶
| Name | Description |
|---|---|
| TEncoding.ANSI | Ansi encoding instance. |
| TEncoding.ASCII | ASCII encoding instance. |
| TEncoding.Default | Default codepage. |
| TEncoding.BigEndianUnicode | Big-endian Unicode (UTF16BE) encoding instance. |
| TEncoding.Unicode | UTF16 encoding instance. |
| TEncoding.UTF7 | UTF7 encoding instance. |
| TEncoding.UTF8 | UTF8 encoding instance. |