Name

Char Type

Description

The Char type represents a single character, just as it does in standard Pascal. You can cast any integer type to a character by using the Char type name in a type cast. Unlike some other type casts, the size of the integer value does not have to match the size of a Char.

You can write a character constant in several different ways:

  • As a string of length 1, e.g., ‘A’ (best for printable characters)

  • As a caret control character, e.g., ^A (good for ANSI control characters, but you should probably give the character a meaningful name, as shown here):

const
  TAB = ^I;
  CRLF = ^M^J;
  • As # followed by an integer constant, e.g., #65 or #$41 (good for control characters, e.g., #0 or #255)

  • By calling the Chr function, e.g., Chr(65) (best for converting integer variables to characters)

  • By typecasting an integer, e.g., Char(65) (same as Chr)

Tips and Tricks

In the current release of Delphi, Char is the same as AnsiChar, but in future versions, the meaning of Char might change. For example, it might become synonymous with WideChar. Char is suitable for most uses, but do not assume that a Char and a Byte occupy the same amount of memory.

See Also

AnsiChar Type, Chr Function, PChar Type, String Keyword, WideChar Type
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset