Name

$Align Compiler Directive

Syntax

{$A+}        // default
{$Align On}  // default
{$A-}
{$Align Off}

Scope

Local

Description

When enabled, the $A or $Align directive aligns class, object, and record fields. When disabled, all structured types are packed. Alignment helps a program run faster, but at the expense of additional memory.

Use the $Align directive at the beginning of a file to affect all declarations in that file. For individual declarations, it’s better to use the packed modifier.

Example

type
{$Align On}
  TPadded = record
    A: Byte;
    B: Integer; // Delphi inserts padding between A and B to align B
  end;
  TPacked = packed record
    A: Byte;
    B: Integer; // no padding because the record is packed
  end;
{$Align Off}
  TUnaligned = record
    A: Byte;
    B: Integer; // no padding because the record is not aligned
  end;

See Also

Packed Keyword

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.