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