Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Show thread progress in modal window (https://www.delphipraxis.net/172754-show-thread-progress-modal-window.html)

WojTec 21. Jan 2013 11:58

Delphi-Version: 5

Show thread progress in modal window
 
Delphi-Quellcode:
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;
But after ShowModal it waiting for ModalResult. How I can use modal window inside thread?

Medium 21. Jan 2013 12:12

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:
FDialog.ModalResult := mrOK;
Then you won't need FDialog.Close anymore as well.

WojTec 21. Jan 2013 12:21

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?

Medium 21. Jan 2013 12:30

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.

Uwe Raabe 21. Jan 2013 12:59

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.

Medium 21. Jan 2013 13:01

AW: Show thread progress in modal window
 
Well, the entire concept is upside down and bogus :)

Uwe Raabe 21. Jan 2013 13:46

AW: Show thread progress in modal window
 
Zitat:

Zitat von Medium (Beitrag 1199959)
Well, the entire concept is upside down and bogus :)

That's why there is no short and correct answer.

WojTec 21. Jan 2013 14:37

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