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.,#65or#$41(good for control characters, e.g., #0 or #255)By calling the
Chrfunction, e.g.,Chr(65)(best for converting integer variables to characters)By typecasting an integer, e.g.,
Char(65)(same asChr)
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 |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access