source: tags/2.10/UWaitingDialog.pas

Last change on this file was 10, checked in by george, 16 years ago

Verze 2.9 a 2.10.

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1unit UWaitingDialog;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, ImgList, ComCtrls, StdCtrls, ExtCtrls;
8
9type
10 TMetoda = procedure of object;
11
12 TWaitingTask = class(TThread)
13 procedure Execute; override;
14 public
15 Cislo: Integer;
16 Nazev: string;
17 Metoda: TMetoda;
18 end;
19
20 TWaitingDialog = class(TForm)
21 ProgressBar1: TProgressBar;
22 Label1: TLabel;
23 ListView1: TListView;
24 ImageList1: TImageList;
25 Label2: TLabel;
26 Timer1: TTimer;
27 Label3: TLabel;
28 Animate1: TAnimate;
29 procedure Timer1Timer(Sender: TObject);
30 procedure FormCreate(Sender: TObject);
31 procedure FormClose(Sender: TObject; var Action: TCloseAction);
32 private
33 FPozice: Real;
34 Ulohy: array of record
35 Operace: TMetoda;
36 Primo: Boolean;
37 end;
38 Chyba: Integer;
39 Uloha: TWaitingTask;
40 WindowList: Pointer;
41 Zacatek: TDateTime;
42 procedure NastavPozici(NovaPozice: Real);
43 public
44 Terminate: Boolean;
45 property Pozice: Real write NastavPozici;
46 procedure PridejUlohu(Nazev: string; Metoda: TMetoda; Primo: Boolean=False);
47 procedure Start;
48 procedure Stop;
49 { Public declarations }
50 end;
51
52var
53 WaitingDialog: TWaitingDialog;
54
55implementation
56
57{$R *.dfm}
58
59procedure TWaitingTask.Execute;
60begin
61 try
62 try
63 Metoda;
64 except
65 raise Exception.Create('V úloze "' + Nazev + '" došlo k vyjímce!');
66 end;
67 finally
68 Terminate;
69 end;
70end;
71
72procedure TWaitingDialog.NastavPozici(NovaPozice: Real);
73begin
74 if (NovaPozice<0) then NovaPozice:= 0;
75 if (NovaPozice>100) then NovaPozice:= 100;
76 if not ProgressBar1.Visible then ProgressBar1.Show;
77 ProgressBar1.Position:= Round(NovaPozice);
78 FPozice:= NovaPozice;
79end;
80
81procedure TWaitingDialog.PridejUlohu(Nazev: string; Metoda: TMetoda; Primo: Boolean=False);
82var
83 Novy: TListItem;
84begin
85 ListView1.Items.BeginUpdate;
86 Novy:= ListView1.Items.Add;
87 with Novy do begin
88 Caption:= Nazev;
89 ImageIndex:= 2;
90 end;
91 SetLength(Ulohy,Length(Ulohy)+1);
92 Ulohy[High(Ulohy)].Operace:= Metoda;
93 Ulohy[High(Ulohy)].Primo:= Primo;
94 ListView1.Items.EndUpdate;
95end;
96
97procedure TWaitingDialog.Start;
98var
99 I: Integer;
100begin
101 try
102 Terminate := False;
103 Chyba:= 0;
104 WindowList := DisableTaskWindows(0);
105 Height:= 90+19*ListView1.Items.Count;
106 Zacatek:= Now;
107 //Show;
108 Timer1.Enabled:= True;
109// Timer1Timer(Self);
110 for I:= 0 to High(Ulohy) do begin
111 ListView1.Items.Item[I].ImageIndex:= 1;
112 Label3.Caption:= '';
113 ProgressBar1.Position:= 0;
114 if Ulohy[I].Primo then Ulohy[I].Operace else begin
115 Uloha := TWaitingTask.Create(True);
116 with Uloha do begin
117 Metoda:= Ulohy[I].Operace;
118 Nazev:= ListView1.Items.Item[I].Caption;
119 Cislo:= I;
120 Resume;
121 while not Terminated do Application.ProcessMessages;
122 WaitFor;
123 Free;
124 end;
125 end;
126 ProgressBar1.Hide;
127 ListView1.Items.Item[I].ImageIndex:= 0;
128 if Chyba>0 then Break;
129 end;
130 finally
131 Timer1.Enabled:= False;
132 EnableTaskWindows(WindowList);
133 if Visible then begin
134 WaitingDialog.Hide;
135 end;
136 SetLength(Ulohy,0);
137 ListView1.Items.BeginUpdate;
138 ListView1.Clear;
139 ListView1.Items.EndUpdate;
140 end;
141end;
142
143procedure TWaitingDialog.Timer1Timer(Sender: TObject);
144begin
145 if not Visible then begin
146 Show;
147 end;
148 if ProgressBar1.Position>4 then
149 Label3.Caption := TimeToStr((Now-Zacatek)/FPozice*(100-FPozice));
150end;
151
152procedure TWaitingDialog.FormCreate(Sender: TObject);
153begin
154 Animate1.FileName := ExtractFileDir(Application.ExeName)+ '\horse.avi';
155 Animate1.Active := True;
156end;
157
158procedure TWaitingDialog.Stop;
159begin
160 Terminate := True;
161end;
162
163procedure TWaitingDialog.FormClose(Sender: TObject; var Action: TCloseAction);
164begin
165 Terminate := True;
166end;
167
168end.
Note: See TracBrowser for help on using the repository browser.