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);
Static Synchronized method is also a method of synchronizing a method in java such that no two threads can act simultaneously static upon the synchronized method. The only difference is by using Static Synchronized.
Yes, we can synchronize a run() method in Java, but it is not required because this method has been executed by a single thread only. Hence synchronization is not needed for the run() method.
One way to avoid synchronization is to make every resource immutable which would be accessed by multiple threads. Making class/object immutable makes sure its threadsafe.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With