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.,^Mfor a carriage return. For special characters, a character constant usually works best, e.g.,#0to mark the end of aPCharstring. UseChrto convert variables.Calling
Chris identical to using a type cast, butChris more familiar to experienced Pascal programmers.
See Also
| AnsiChar Type, Char Type, Ord Function, 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