Delphi Error – E2071 This type cannot be initialized

Delphi Compiler Error

E2071 This type cannot be initialized

Reason for the Error & Solution

File types (including type Text), and the type Variant cannot be initialized, that is, you cannot declare typed constants or initialized variables of these types.

program Produce;

var
  V: Variant = 0;

begin
end.

The example tries to declare an initialized variable of type Variant, which illegal.

program Solve;

var
  V: Variant;

begin
  V := 0;
end.

The solution is to initialize a normal variable with an assignment statement.

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...