E2195 Cannot initialize local variables (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Error and Warning Messages (Delphi)

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.

Retrieved from "https://docwiki.embarcadero.com/RADStudio/Tokyo/e/index.php?title=E2195_Cannot_initialize_local_variables_(Delphi)&oldid=255697"