Compiler Directive
Sets the minimum storage used to hold enumerated types
1   {$MinEnumSize 1}
2   {$MinEnumSize 2}
3   {$MinEnumSize 4}
The $MinEnumSize compiler directive sets the minimum storage size, in bytes, that enumerated types will take.
This is set to 1 byte by default, thereby providing capacity for 256 enumerations.
If you exceed the current storage size, by either defining rather a lot of enumeration values (over 256), or, more likely, defining enumeration values exceeding 256, then a larger storage size is used. The $MinEnumSize directive simply defines the minimum number of bytes to use (see the example).
$MinEnumSize is equivalent to $Z.

It can be set many times in your code.

The default value is $MinEnumSize 1.
Related commands
$Z Sets the minimum storage used to hold enumerated types
 Author links

 Buy Website Traffic at

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

Example code : Various enum type sizes
// 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);

  {$MinEnumSize 1}
  TCars1  = (Rover, Jaguar, Honda);    // Will fit into 1 byte
  TFruit1 = (Banana=255, Apple, Pear); // Will exceed one byte

  {$MinEnumSize 4}
  TCars2  = (Ford, Nissan, Vauxhall);  // Now uses 4 bytes
  TFruit2 = (Orange=255, Plum, Grape); // Now uses 4 bytes

  ShowMessage('TCars1  size = '+IntToStr(SizeOf(TCars1)));
  ShowMessage('TFruit1 size = '+IntToStr(SizeOf(TFruit1)));
  ShowMessage('TCars2  size = '+IntToStr(SizeOf(TCars2)));
  ShowMessage('TFruit2 size = '+IntToStr(SizeOf(TFruit2)));
Hide full unit code
   TCars1  size = 1
   TFruit1 size = 2
   TCars2  size = 4
   TFruit2 size = 4
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page