AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Show thread progress in modal window

Ein Thema von WojTec · begonnen am 21. Jan 2013 · letzter Beitrag vom 21. Jan 2013
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Show thread progress in modal window

  Alt 21. Jan 2013, 10:58
Delphi-Version: 5
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?
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.679 Beiträge
 
Delphi 2007 Enterprise
 
#2

AW: Show thread progress in modal window

  Alt 21. Jan 2013, 11:12
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: FDialog.ModalResult := mrOK; Then you won't need FDialog.Close anymore as well.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#3

Re: Show thread progress in modal window

  Alt 21. Jan 2013, 11:21
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?
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.679 Beiträge
 
Delphi 2007 Enterprise
 
#4

AW: Show thread progress in modal window

  Alt 21. Jan 2013, 11:30
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.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.021 Beiträge
 
Delphi 12 Athens
 
#5

AW: Show thread progress in modal window

  Alt 21. Jan 2013, 11:59
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.
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.679 Beiträge
 
Delphi 2007 Enterprise
 
#6

AW: Show thread progress in modal window

  Alt 21. Jan 2013, 12:01
Well, the entire concept is upside down and bogus
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.021 Beiträge
 
Delphi 12 Athens
 
#7

AW: Show thread progress in modal window

  Alt 21. Jan 2013, 12:46
Well, the entire concept is upside down and bogus
That's why there is no short and correct answer.
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#8

Re: Show thread progress in modal window

  Alt 21. Jan 2013, 13:37
I tried component for it and then I did similar with my thread class - working
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:19 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz