Question

procedure TGridThread.Execute;
var
  i: integer;
  iIEBitmap: TIEBitmap;
  iWidth: integer;
  iHeight: integer;
  iImageCount: integer;
  iArrayOfBitmaps: array of TBitmap;
begin
  inherited;
  { Free the thread onTerminate }
  FreeOnTerminate := True;
  if not Terminated then
    begin    
      if not Terminated then
      begin
        Synchronize(
         procedure
           begin
              iIEBitmap := TIEBitmap.Create(Form1.ImageEnView1.IEBitmap);
              iWidth := Form1.ImageEnMView1.ImageOriginalWidth[0];
              iHeight := (Form1.ImageEnMView1.ImageOriginalHeight[0] + iSpaceBetweenImages) *
              Form1.ImageEnMView1.ImageCount;
              iImageCount := Form1.ImageEnMView1.ImageCount;
            end);

           SetLength(iArrayOfBitmaps, iImageCount);

           Synchronize(
            procedure
            begin
              for i := 0 to iImageCount - 1 do // [DCC Error] Unit1.pas(334): E1019 For loop control variable must be simple local variable
              begin
                iArrayOfBitmaps[i] := Form1.ImageEnMView1.GetBitmap(i);
                { Free the bitmap }
                Form1.ImageEnMView1.ReleaseBitmap(0);
               end;
            end);
Was it helpful?

Solution

You simply need to declare a local variable for your loop counter:

Synchronize(
  procedure
  var
    i: Integer;
  begin
    for i := 0 to iImageCount - 1 do
    begin
      iArrayOfBitmaps[i] := Form1.ImageEnMView1.GetBitmap(i);
      Form1.ImageEnMView1.ReleaseBitmap(0);
    end;
  end
);

A loop variable must be local to the procedure in which the loop appears. In your code you had declared the variable as a local in a different procedure. And hence the compilation error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top