Delphi Error – E2418 Type ‘%s’ needs initialization – not allowed in variant record

Delphi Compiler Error

E2418 Type ‘%s’ needs initialization – not allowed in variant record

Reason for the Error & Solution

Type needs initialization – not allowed in variant record. Variant records do not allow types that need initialization in their variant field list since each variant field references the same memory location. As an example, the following code will not compile because the array type needs to be initialized.

program Project3;

{$APPTYPE CONSOLE}

type
  TFoo = record
    case Boolean of
      True: (bar: Integer);
      False: (baz: array [0..2] of Integer);
  end;

end.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...