HomeDelphiDelphi Error – X1019 For loop control variable must be simple local variable

Delphi Error – X1019 For loop control variable must be simple local variable

Delphi Compiler Error

X1019 For loop control variable must be simple local variable

Reason for the Error & Solution

This error message is given when the control variable of a for statement is not a simple variable (but a component of a record, for instance), or if it is not local to the procedure containing the for statement.

For backward compatibility reasons, it is legal to use a global variable as the control variable – the compiler gives a warning in this case. Note that using a local variable will also generate more efficient code.

program Produce;

var
  I: Integer;
  A: array [0..9] of Integer;

procedure Init;
begin
  for I := Low(A) to High(a) do  (*<-- Warning given here*)
    A[I] := 0;
end;

begin
  Init;
end.
	program Solve;
var
  A: array [0..9] of Integer;

procedure Init;
var
  I: Integer;
begin
  for I := Low(A) to High(a) do
    A[I] := 0;
end;

begin
  Init;
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...