Delphi Error – E2195 Cannot initialize local variables

Delphi Compiler Error

E2195 Cannot initialize local variables

Reason for the Error & Solution

The compiler disallows the use of initialized local variables.

program Produce;

  var
    j : Integer;

  procedure Show;
    var i : Integer = 151;
  begin
  end;

begin
end.

The declaration and initialization of ‘i’ in procedure ‘Show’ is illegal.

program Solve;

  var
    j : Integer;

  procedure Show;
    var i : Integer;
  begin
    i := 151;
  end;

begin
  j := 0;
end.

You can use a programmatic style to set all variables to known values.

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