DelphiBasics
$Z
Compiler Directive
Sets the minimum storage used to hold enumerated types
1   {$Z1}
2   {$Z2}
3   {$Z4}
Description
The $Z 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 $Z 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 $Z1.
Related commands
$MinEnumSize Sets the minimum storage used to hold enumerated types
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

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


 
Example code : Various enum type sizes
type
  {$Z1}
  TCars1  = (Rover, Jaguar, Honda);    // Will fit into 1 byte
  TFruit1 = (Banana=255, Apple, Pear); // Will exceed one byte

  {$Z4}
  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
 
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page