How to fix, images loaded in multi thread sometimes don’t show up on the form

  

In my manga viewer i try to load a large number of images (around 200), i try loading these images inside an anonymous thread and when the loading finishes i call a Thread.synchronize, this works fine, but in some cases i keep seeing some images not drawn on the form (I think they are loaded because i can see the information about the image), how can i solve this?

This issue only happens in multi thread so i decided to set the image visible to false and then at the end of the loading inside a Thread.synchronize turn the visible to true, i had hoped this would force some kind of refresh or redraw, but the problem i mentioned consists

TThread.CreateAnonymousThread(procedure
begin
for imageIndex := 0 to fileList.count – 1 do
begin
filePath := fileList[imageIndex]
//Please note that mImageList is an array of FMX.Objects.TImage
//which was filled when the Form is created (I create 300 TImage
//at Form create and later i load the images to the bitmap when
//the user clicks on a new directory(Chapter)

mImageList[imageIndex].beginUpdate();
try
mImageList[imageIndex].loadFromFile(filePath);
mImageList[imageIndex].tagString := filePath;
mImageList[imageIndex].Scale := mImageScale;
mImageList[imageIndex].Visible := false;
except
mImageList[imageIndex].EmptyBitmaps;
end;
mImageList[imageIndex].endUpdate();
end;

TThread.Synchronize(nil, procedure
var
I: Integer;
begin
for I := Low(mImageList) to High(mImageList) do
begin
mImageList[I].Visible := true;
end;
end);
end).Start;

I expect that when i scroll down through the images loaded on the form, i can see them all and they all get drawn on the form properly.

Comments are closed.