DelphiBasics
AnsiChar
Type
A character type guaranteed to be 8 bits in size System unit
  type AnsiChar = #0..#255;
Description
The AnsiChar type is used to hold single characters. It is guaranteed to be 8 bits in size.
 
At the time of writing, it is the same size as Char but the latter may change in the future.
 
It can be assigned from a character or integer value.
Related commands
AnsiString A data type that holds a string of AnsiChars
Char Variable type holding a single character
PAnsiChar A pointer to an AnsiChar value
WideChar Variable type holding a single International character
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

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




 
Example code : Different ways of assigning to and from an AnsiChar
// 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
  myChar  : AnsiChar;

begin
  myChar := 'G';                    // Assign from a character constant
  ShowMessage('Letter G = '+myChar);

  myChar := #65;                    // Assign from an integer constant
  ShowMessage('#65 = '+myChar);

  myChar := ^I;                     // Assign from a control char - tab
  ShowMessage('Control '+myChar+' character');

  myChar := Chr(66);                // Using Chr to convert a number
  ShowMessage('Chr(66) = '+myChar);

  myChar := Char(67);               // Using Char as a standard cast
  ShowMessage('Char(67) = '+myChar);
end;
 
end.
Hide full unit code
   Letter G = G
   #65 = A
   Control    character
   Chr(66) = B
   Char(67) = C
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page