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 dialog when processing data (https://www.delphipraxis.net/161356-show-dialog-when-processing-data.html)

WojTec 30. Jun 2011 07:35

Delphi-Version: 2010

Show dialog when processing data
 
Here is pseudocode which demonstrate what I want to tell:

Delphi-Quellcode:
CreateAndShowDialog();

MakeSomeTaskWhichNeedManyCPUTime()

DestroyDialog();
Dialog contain animated marquee. Normally I'm, creating it, showing in modal mode and then call Invalidate(), but then Windows don't refresh animation. How to show this dialog during data processing and do not lock it update?

Memnarch 30. Jun 2011 08:23

AW: Show dialog when processing data
 
depends on the purpose. If you have a plain marquee, just call refresh or repaint on the dialog after each finished step.

If you need a clean animation without steps and the shiny animation from vista/7, you'll have to put your cpu heavy task into a thread.


Greets
Memnarch

Luckie 30. Jun 2011 08:45

AW: Show dialog when processing data
 
Code:
CreateThread
OnBeginThread ShowDialog
Run thread
OnEndThread CloseDialog
DestroyThread

WojTec 30. Jun 2011 13:02

Re: Show dialog when processing data
 
Thanks guys. Depend on your advices I made this:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  JvThread1.Execute(Self);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if not JvThread1.Terminated then
    JvThread1.Terminate
  ;
end;

procedure TForm1.JvThread1Begin(Sender: TObject);
begin
  ProcessingDialog := TProcessingDialog.Create('Heavy Task');
  ProcessingDialog.Show;
end;

procedure TForm1.JvThread1CancelExecute(CurrentThread: TJvThread);
begin
  JvThread1Finish(Self);
end;

procedure TForm1.JvThread1Execute(Sender: TObject; Params: Pointer);
var
  I: Integer;
begin
  for I := 0 to 100000 do
  begin
    TForm1(Params).Value := I;
    JvThread1.Synchronize(TForm1(Params).UpdateStatus);

    if JvThread1.Terminated then
      Break
    ;
  end;
end;

procedure TForm1.JvThread1Finish(Sender: TObject);
begin
  ProcessingDialog.Free;
end;

procedure TForm1.UpdateStatus;
begin
  Caption := IntToStr(Value);
end;
Yes, I know, is completely lame, because uses component. But is simple :D

So, it working if I just open dialog, but I want to modal dialog (to lock access to interface), but when ShowModal(), thread don't execute. There is solution on this?

DeddyH 30. Jun 2011 13:05

AW: Show dialog when processing data
 
Process your data within the modal dialog form.


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:07 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