How can i make sure the form is clean and repainted ?, some Timage remains on the screen even after i empty the bitmap

  

I have a program which allows the user to click on a directory and the program will start loading all the images there and shows them on the screen and the user can view them by scrolling down
Now here is the issue, after the program loads a directory, if the user clicks on another directory, after loading the new directory some times there are remains of the previous images on the screen (Form) !, now here is the thing, if i for example try focusing another controller(component) and then i click on the form, the remains will get cleaned! so it seems the problem lies with the fact the form is not repainted or something like that!
Here is what you need to know about my program :
1-What i said happens in Fullscreen
2-I am in FMX and i use TImage
In the end i should mention that i have already tried using form1.invalidate;, which cleans the remains of something like an image resize but doesn’t work on the image remains (when i say remains i mean a whole picture not residues)

Update 01:
Honestly it was fairly hard to reproduce this problem, i tried my best and i think this example kinda shows what i am talking about, i think the issue arises from the fact that i am doing my loading and cleaning in another thread, because i was not able to reproduce this problem in a single thread application
Here is the test case code:

unit Unit2;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls, System.Generics.Collections,
FMX.Objects;

type
TForm2 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;
mImageList: TList<TImage>;
mSwitch: boolean;

implementation
uses
Threading;

{$R *.fmx}

procedure TForm2.FormCreate(Sender: TObject);
var
cImage: TImage;
I: Integer;
begin
mImageList := TList<TImage>.create;
mSwitch := false;

for I := 0 to 3 do
begin
cImage := TImage.Create(nil);
cImage.Parent := Form2;
mImageList.Add(cImage);
end;

Form2.FullScreen := true;
timer1.Interval := 3000;
end;

procedure TForm2.Timer1Timer(Sender: TObject);

begin

TThread.CreateAnonymousThread(procedure
var
I: Integer;
heightSum: single;
path: string;
begin
if not(mSwitch) then
path := ‘images\1\1 (‘
else
path := ‘images\2\2 (‘;

heightSum := 0;

for I := 0 to mImageList.Count – 1 do
begin
mImageList[I].Bitmap := nil;
end;

for I := 0 to mImageList.Count – 1 do
begin
mImageList[I].Bitmap.LoadFromFile(path + (i + 1).ToString + ‘).jpg’);
mImageList[I].Width := mImageList[I].Bitmap.Width;
mImageList[I].Height := mImageList[I].Bitmap.Height;
mImageList[I].Position.X := Form2.Width / 2 – mImageList[I].Width / 2;
mImageList[I].Position.Y := heightSum;
heightSum := heightSum + mImageList[I].Height;
end;

TThread.Synchronize(nil, procedure
begin
end);
end).Start;

mSwitch := not(mSwitch);
end;

end.

Comments are closed.