How can i make sure the form is clean and repainted ?, some Timage remains on the screen even after i empty...
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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 := 'images11 ('
else
path := 'images22 (';
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.
multithreading delphi firemonkey
|
show 6 more comments
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 := 'images11 ('
else
path := 'images22 (';
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.
multithreading delphi firemonkey
1
I removed the delphi-xe tag since you clearly are not using that version, which predates FMX. I added the firemonkey tag. Now, could you please add a Minimal, Complete, and Verifiable example so that we can see code that demonstrates the problem. Without this the question will be closed.
– David Heffernan
Nov 22 '18 at 8:46
@DavidHeffernan, I tried to create a minimal example, for one thing i noticed i couldn't recreate my problem in a single thread application so i tried a multithread approach like my original program, and i "kinda" got a similar result, hope this shows where i went wrong.
– ali ahmadi
Nov 22 '18 at 9:26
1
Your asumption is correct. The problems you are expiriencig are caused by unproper use of multithreading. All the code that is interacting tih any viasual FMX components should be executed from withing anonymus method you pass toTThread.Synchronize
.
– SilverWarior
Nov 22 '18 at 9:28
1
@aliahmadi Why do you need to pre-load the images. Couldn't you just load them right before they are being shown. That is how Windows Excplorer Works when you using preview feature in folder with images.
– SilverWarior
Nov 22 '18 at 9:33
2
The fact that you want to improve the performance of your program does not mean that you can simply ignore the rules!
– David Heffernan
Nov 22 '18 at 10:02
|
show 6 more comments
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 := 'images11 ('
else
path := 'images22 (';
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.
multithreading delphi firemonkey
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 := 'images11 ('
else
path := 'images22 (';
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.
multithreading delphi firemonkey
multithreading delphi firemonkey
edited Nov 22 '18 at 9:23
ali ahmadi
asked Nov 22 '18 at 8:42
ali ahmadiali ahmadi
6813
6813
1
I removed the delphi-xe tag since you clearly are not using that version, which predates FMX. I added the firemonkey tag. Now, could you please add a Minimal, Complete, and Verifiable example so that we can see code that demonstrates the problem. Without this the question will be closed.
– David Heffernan
Nov 22 '18 at 8:46
@DavidHeffernan, I tried to create a minimal example, for one thing i noticed i couldn't recreate my problem in a single thread application so i tried a multithread approach like my original program, and i "kinda" got a similar result, hope this shows where i went wrong.
– ali ahmadi
Nov 22 '18 at 9:26
1
Your asumption is correct. The problems you are expiriencig are caused by unproper use of multithreading. All the code that is interacting tih any viasual FMX components should be executed from withing anonymus method you pass toTThread.Synchronize
.
– SilverWarior
Nov 22 '18 at 9:28
1
@aliahmadi Why do you need to pre-load the images. Couldn't you just load them right before they are being shown. That is how Windows Excplorer Works when you using preview feature in folder with images.
– SilverWarior
Nov 22 '18 at 9:33
2
The fact that you want to improve the performance of your program does not mean that you can simply ignore the rules!
– David Heffernan
Nov 22 '18 at 10:02
|
show 6 more comments
1
I removed the delphi-xe tag since you clearly are not using that version, which predates FMX. I added the firemonkey tag. Now, could you please add a Minimal, Complete, and Verifiable example so that we can see code that demonstrates the problem. Without this the question will be closed.
– David Heffernan
Nov 22 '18 at 8:46
@DavidHeffernan, I tried to create a minimal example, for one thing i noticed i couldn't recreate my problem in a single thread application so i tried a multithread approach like my original program, and i "kinda" got a similar result, hope this shows where i went wrong.
– ali ahmadi
Nov 22 '18 at 9:26
1
Your asumption is correct. The problems you are expiriencig are caused by unproper use of multithreading. All the code that is interacting tih any viasual FMX components should be executed from withing anonymus method you pass toTThread.Synchronize
.
– SilverWarior
Nov 22 '18 at 9:28
1
@aliahmadi Why do you need to pre-load the images. Couldn't you just load them right before they are being shown. That is how Windows Excplorer Works when you using preview feature in folder with images.
– SilverWarior
Nov 22 '18 at 9:33
2
The fact that you want to improve the performance of your program does not mean that you can simply ignore the rules!
– David Heffernan
Nov 22 '18 at 10:02
1
1
I removed the delphi-xe tag since you clearly are not using that version, which predates FMX. I added the firemonkey tag. Now, could you please add a Minimal, Complete, and Verifiable example so that we can see code that demonstrates the problem. Without this the question will be closed.
– David Heffernan
Nov 22 '18 at 8:46
I removed the delphi-xe tag since you clearly are not using that version, which predates FMX. I added the firemonkey tag. Now, could you please add a Minimal, Complete, and Verifiable example so that we can see code that demonstrates the problem. Without this the question will be closed.
– David Heffernan
Nov 22 '18 at 8:46
@DavidHeffernan, I tried to create a minimal example, for one thing i noticed i couldn't recreate my problem in a single thread application so i tried a multithread approach like my original program, and i "kinda" got a similar result, hope this shows where i went wrong.
– ali ahmadi
Nov 22 '18 at 9:26
@DavidHeffernan, I tried to create a minimal example, for one thing i noticed i couldn't recreate my problem in a single thread application so i tried a multithread approach like my original program, and i "kinda" got a similar result, hope this shows where i went wrong.
– ali ahmadi
Nov 22 '18 at 9:26
1
1
Your asumption is correct. The problems you are expiriencig are caused by unproper use of multithreading. All the code that is interacting tih any viasual FMX components should be executed from withing anonymus method you pass to
TThread.Synchronize
.– SilverWarior
Nov 22 '18 at 9:28
Your asumption is correct. The problems you are expiriencig are caused by unproper use of multithreading. All the code that is interacting tih any viasual FMX components should be executed from withing anonymus method you pass to
TThread.Synchronize
.– SilverWarior
Nov 22 '18 at 9:28
1
1
@aliahmadi Why do you need to pre-load the images. Couldn't you just load them right before they are being shown. That is how Windows Excplorer Works when you using preview feature in folder with images.
– SilverWarior
Nov 22 '18 at 9:33
@aliahmadi Why do you need to pre-load the images. Couldn't you just load them right before they are being shown. That is how Windows Excplorer Works when you using preview feature in folder with images.
– SilverWarior
Nov 22 '18 at 9:33
2
2
The fact that you want to improve the performance of your program does not mean that you can simply ignore the rules!
– David Heffernan
Nov 22 '18 at 10:02
The fact that you want to improve the performance of your program does not mean that you can simply ignore the rules!
– David Heffernan
Nov 22 '18 at 10:02
|
show 6 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426895%2fhow-can-i-make-sure-the-form-is-clean-and-repainted-some-timage-remains-on-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426895%2fhow-can-i-make-sure-the-form-is-clean-and-repainted-some-timage-remains-on-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I removed the delphi-xe tag since you clearly are not using that version, which predates FMX. I added the firemonkey tag. Now, could you please add a Minimal, Complete, and Verifiable example so that we can see code that demonstrates the problem. Without this the question will be closed.
– David Heffernan
Nov 22 '18 at 8:46
@DavidHeffernan, I tried to create a minimal example, for one thing i noticed i couldn't recreate my problem in a single thread application so i tried a multithread approach like my original program, and i "kinda" got a similar result, hope this shows where i went wrong.
– ali ahmadi
Nov 22 '18 at 9:26
1
Your asumption is correct. The problems you are expiriencig are caused by unproper use of multithreading. All the code that is interacting tih any viasual FMX components should be executed from withing anonymus method you pass to
TThread.Synchronize
.– SilverWarior
Nov 22 '18 at 9:28
1
@aliahmadi Why do you need to pre-load the images. Couldn't you just load them right before they are being shown. That is how Windows Excplorer Works when you using preview feature in folder with images.
– SilverWarior
Nov 22 '18 at 9:33
2
The fact that you want to improve the performance of your program does not mean that you can simply ignore the rules!
– David Heffernan
Nov 22 '18 at 10:02