DelphiBasics
Chr
Function
Convert an integer into a character System unit
1  function Chr ( IntValue : Integer ) : AnsiChar;
2  function Chr ( IntValue : Integer ) : WideChar;
Description
The Chr function converts an IntValue integer into either an AnsiChar or WideChar as appropriate.
Notes
The ansi character set includes control characters such as Chr(27) meaning escape.

Chr(65) gives 'A'

Note that ^A is equivalent to Char(1).
Related commands
Char Variable type holding a single character
Ord Provides the Ordinal value of an integer, character or enum
Val Converts number strings to integer and floating point values
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.




 
Example code : Showing Chr and ^ usage
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  // The System unit does not need to be defined
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  tab  : char;
  crlf : string;
begin
  // Show the use of Chr
  tab := Chr(9);
  crlf := Chr(13)+Chr(10);
  ShowMessage('Hello'+tab+'World');
  ShowMessage('');
  ShowMessage('Hello'+crlf+'World');
  ShowMessage('');

  // Show the equivalent use of ^
  tab := ^I;  // I = 9th capital of the alphabet
  crlf := ^M^J;  // M = 13th, J = 10th letters
  ShowMessage('Hello'+tab+'World');
  ShowMessage('');
  ShowMessage('Hello'+crlf+'World');
end;
 
end.
Hide full unit code
   Hello   World
  
   Hello
   World
  
   Hello   World
  
   Hello
   World
  
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page