Compiler Directive
Treat string types as AnsiString or ShortString
1   {$LongStrings Off}
2   {$LongStrings On}
The $LongStrings compiler directive determines whether Delphi treats the string type as an AnsiString when on (default) or ShortString when off.
The default recognises that the general use of string types is to hold data that is likely to be longer than 255 characters (ShortString capacity).
$LongStrings is equivalent to $H.

$LongStrings can be used multiple times in your code, but this is not recommended (except for illustration purposes in the example).

The default value is $LongStrings On
Related commands
$H Treat string types as AnsiString or ShortString
AnsiString A data type that holds a string of AnsiChars
ShortString Defines a string of up to 255 characters
String A data type that holds a string of characters
 Author links

 Buy Website Traffic at

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

Example code : Packing a record to reduce storage
// 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;
  Forms, Dialogs;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
Form1: TForm1;
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);

  // Define littleString to be treated as a ShortString
  {$LongStrings Off}
  littleString : string;

  // Define bigString to be treated as an AnsiString
  {$LongStrings On}
  bigString : string;
  // Show the size of the little string - 256 bytes
  ShowMessageFmt('littleString size = %d',[SizeOf(littleString)]);

  // Show the size of the big string - 4 - a pointer to text
  ShowMessageFmt('   bigString size = %d',[SizeOf(bigString)]);
Hide full unit code
   littleString size = 256
      bigString size = 4
Delphi Programming Neil Moffatt 2002 - 2018. All rights reserved.  |  Home Page