1 {$MinEnumSize 1}
2 {$MinEnumSize 2}
3 {$MinEnumSize 4}
Description
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).
Notes
$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
Example code : Various enum type sizes
type
{$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
begin
ShowMessage('TCars1 size = '+IntToStr(SizeOf(TCars1)));
ShowMessage('TFruit1 size = '+IntToStr(SizeOf(TFruit1)));
ShowMessage('TCars2 size = '+IntToStr(SizeOf(TCars2)));
ShowMessage('TFruit2 size = '+IntToStr(SizeOf(TFruit2)));
end;
Show full unit code
TCars1 size = 1
TFruit1 size = 2
TCars2 size = 4
TFruit2 size = 4