-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUFormViewFindProgress.pas
166 lines (142 loc) · 3.59 KB
/
UFormViewFindProgress.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
unit UFormViewFindProgress;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
StdCtrls, ComCtrls, ATBinHex, ATViewer, ExtCtrls,
TntStdCtrls,
ATStreamSearch;
type
TFormViewFindProgress = class(TForm)
btnCancel: TButton;
ProgressBar1: TProgressBar;
labSearch: TTntLabel;
Timer1: TTimer;
labPercent: TLabel;
Timer2: TTimer;
procedure btnCancelClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
FViewer: TATViewer;
FFindText: WideString;
FFindTextOrig: WideString;
FFindOptions: TATStreamSearchOptions;
FFindFirst: boolean;
FFindPrevious: boolean;
FCancel: boolean;
FShowNoErrorMsg: boolean;
procedure StartSearch;
procedure Progress(const ACurrentPos, AMaximalPos: Int64; var AContinue: boolean);
end;
implementation
uses
ATxSProc, ATxMsgProc, ATxMsg, ATxUtils,
ATViewerMsg;
{$R *.DFM}
procedure TFormViewFindProgress.Progress(const ACurrentPos, AMaximalPos: Int64; var AContinue: boolean);
var
Percent: integer;
begin
if AMaximalPos > 0 then
Percent:= ACurrentPos * 100 div AMaximalPos
else
Percent:= 0;
labSearch.Caption:= SFormatW(MsgViewerSearchProgress, [FFindTextOrig]);
labPercent.Caption:= Format('%d%%', [Percent]);
ProgressBar1.Position:= Percent;
Application.ProcessMessages;
AContinue:= not FCancel;
end;
procedure TFormViewFindProgress.StartSearch;
begin
ShowModal;
end;
procedure TFormViewFindProgress.FormCreate(Sender: TObject);
begin
//Init fields
FViewer:= nil;
FFindText:= '';
FFindTextOrig:= '';
FFindOptions:= [];
FFindFirst:= true;
FFindPrevious:= false;
FCancel:= false;
FShowNoErrorMsg:= false;
end;
procedure TFormViewFindProgress.FormShow(Sender: TObject);
var
En: boolean;
begin
{$I Lang.FormViewFindProgress.inc}
FViewer.OnTextSearchProgress:= Progress;
FCancel:= false;
labSearch.Caption:= SFormatW(MsgViewerSearchProgress, [FFindTextOrig]);
labPercent.Caption:= '0%';
ProgressBar1.Position:= 0;
En:= FViewer.Mode in [vmodeText, vmodeBinary, vmodeHex, vmodeUnicode];
ProgressBar1.Enabled:= En;
btnCancel.Enabled:= En;
Timer1.Enabled:= true;
Timer2.Enabled:= true;
AlphaBlendValue:= 0;
end;
procedure TFormViewFindProgress.btnCancelClick(Sender: TObject);
begin
FCancel:= true;
end;
procedure TFormViewFindProgress.Timer1Timer(Sender: TObject);
var
AResultOK,
ASearchOK: boolean;
begin
Timer1.Enabled:= false;
ASearchOK:= true;
try
if FFindFirst then
AResultOK:= FViewer.FindFirst(FFindText, FFindOptions)
else
AResultOK:= FViewer.FindNext(FFindPrevious);
except
on E: Exception do
begin
AResultOK:= false;
ASearchOK:= false;
if E.Message<>'' then
MsgError(E.Message, Handle)
else
MsgError(MsgString(0124), Handle);
end;
end;
Hide;
if not ASearchOK then
begin
//Nothing currently
end
else
if not AResultOK then
begin
if FShowNoErrorMsg then
MessageBeep(MB_ICONEXCLAMATION)
else
MsgWarning(SFormatW(MsgViewerErrCannotFindText, [FFindTextOrig]), Handle);
end;
ModalResult:= mrOk;
end;
procedure TFormViewFindProgress.Timer2Timer(Sender: TObject);
var
N: Integer;
begin
if AlphaBlendValue < 5 then N := 1 else N := 50;
AlphaBlendValue := AlphaBlendValue + N;
if AlphaBlendValue >= 250 then
begin
Timer2.Enabled := false;
AlphaBlendValue := 255;
end;
end;
end.