-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuformtask.pas
121 lines (95 loc) · 2.32 KB
/
uformtask.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
unit uFormTask;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
LMessages;
const
LM_MSG_Progress = LM_USER + 2000;
type
{ TFormTaskProg }
TFormTaskProg = class(TForm)
ButtonCancel: TButton;
Label1: TLabel;
ProgressBar1: TProgressBar;
procedure ButtonCancelClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
FLastTime:LongWord;
FCancelPressed:Boolean;
FWorker: TNotifyEvent;
function GetCancelRes: Boolean;
function GetPos: Integer;
procedure SetPos(AValue: Integer);
procedure SetWorker(AValue: TNotifyEvent);
protected
procedure IncMessage(var Msg); message LM_MSG_Progress;
public
function IncPos:Boolean;
property Position:Integer read GetPos write SetPos;
property CancelRes:Boolean read GetCancelRes;
end;
var
FormTaskProg: TFormTaskProg;
implementation
{$R *.lfm}
uses
DefaultTranslator, LCLMessageGlue;
{ TFormTaskProg }
function TFormTaskProg.GetPos: Integer;
begin
Result:=ProgressBar1.Position;
end;
procedure TFormTaskProg.ButtonCancelClick(Sender: TObject);
begin
FCancelPressed:=True;
end;
procedure TFormTaskProg.FormCreate(Sender: TObject);
begin
end;
procedure TFormTaskProg.FormShow(Sender: TObject);
begin
FLastTime:=GetTickCount;
FCancelPressed:=False;
ProgressBar1.Position:=0;
end;
function TFormTaskProg.GetCancelRes: Boolean;
begin
Result:=FCancelPressed;
end;
procedure TFormTaskProg.SetPos(AValue: Integer);
begin
ProgressBar1.Position:=AValue;
end;
procedure TFormTaskProg.SetWorker(AValue: TNotifyEvent);
begin
if FWorker=AValue then Exit;
FWorker:=AValue;
end;
procedure TFormTaskProg.IncMessage(var Msg);
begin
if ProgressBar1.Position<ProgressBar1.Max then
ProgressBar1.StepBy(1)
else
ProgressBar1.Position:=0;
Label1.Caption:=StringOfChar('.',ProgressBar1.Position+1);
end;
function TFormTaskProg.IncPos: Boolean;
var
CurTick, DiffTick:Integer;
begin
Result:=False;
CurTick:=GetTickCount;
if FLastTime>CurTick then
DiffTick:=longword(-1)-FLastTime+CurTick
else
DiffTick:=CurTick-FLastTime;
if DiffTick>100 then begin
FLastTime:=CurTick;
Result:=True;
SendSimpleMessage(self,LM_MSG_Progress);
Application.ProcessMessages;
end;
end;
end.