![]() |
Delphi-Version: 5
Show thread progress in modal window
Delphi-Quellcode:
But after ShowModal it waiting for ModalResult. How I can use modal window inside thread?
type
TCheckThread = class(TThread) private FDialog: TProcessingDialog; procedure DoCheck; protected procedure Execute; override; public constructor Create(CreateSuspended: Boolean); destructor Destroy; override; end; constructor TCheckThread.Create(CreateSuspended: Boolean); begin inherited Create(CreateSuspended); FDialog := TProcessingDialog.Create(Application); FDialog.ShowModal; end; destructor TCheckThread.Destroy; begin FDialog.Free; inherited Destroy; end; procedure TCheckThread.DoCheck; var //... begin MainForm.lblHint.Visible := False; FDialog.tbProgress.Max := MainForm.CheckedCount; for I := 0 to MainForm.lvList.Items.Count - 1 do begin if Terminated then Exit; //... end; FDialog.Close; end; procedure TCheckThread.Execute; begin Synchronize(DoCheck); end; |
AW: Show thread progress in modal window
Do you do eveything in your DoCheck Method? If so, executing eveything synchronizied defies the cause for a thread entirely. To your question: You can just set the ModalResult by yourself in code when the task has completed:
Delphi-Quellcode:
Then you won't need FDialog.Close anymore as well.
FDialog.ModalResult := mrOK;
|
Re: Show thread progress in modal window
Don't understand what I should do?
I want to perform checking procedure in thread, because that's quite long process. What is going on I want to show on list and on modal window (current data and progress bar). So, what to do to do it? |
AW: Show thread progress in modal window
The problem is, that by having all the thread's code execute synchronized, you effectively have it running in the main-thread of your normal windows. (That is the purpose of synchronizing.) Depending on whether you have that level of control over the long process (i.e. it is your code), scrapping the thread and instead work with a sort of OnProgress() Event should be better suited for this.
Another thing: If you have the process (calculations or whatever) running in the main thread, but do display tasks in a separate thread, you basically are doing things backwards. Put the long running process into a thread, and have it send messages about it's status to a normal form to do status displays on. That would be the proper way. |
AW: Show thread progress in modal window
Has anyone realized (except the OP) that the TCheckThread.Create will not succeed while the modal window is open? So no Execute or DoCheck or Synchronize is run.
|
AW: Show thread progress in modal window
Well, the entire concept is upside down and bogus :)
|
AW: Show thread progress in modal window
Zitat:
|
Re: Show thread progress in modal window
I tried component for it and then I did similar with my thread class - working :)
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:55 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz