Name
Chr Function
Syntax
function Chr(IntValue: Integer): AnsiChar; function Chr(IntValue: Integer): WideChar;
Description
The Chr
function
converts an integer to its equivalent character, either
AnsiChar
or WideChar
, whichever
is called for. Chr
is not a real function, and
calling Chr
has no runtime impact. Delphi
automatically maps IntValue
into the range needed
for the character type
(#0
..#255
for
AnsiChar
or
#0
..#65535
for
WideChar
).
Tips and Tricks
The compiler treats the character expressions
Chr(27)
,#27
, and^[
identically, so choose the style you find most readable. For control characters, the caret notation is often best, e.g.,^M
for a carriage return. For special characters, a character constant usually works best, e.g.,#0
to mark the end of aPChar
string. UseChr
to convert variables.Calling
Chr
is identical to using a type cast, butChr
is more familiar to experienced Pascal programmers.
See Also
AnsiChar Type, Char Type, Ord Function, WideChar Type |
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.