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 E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...