forked from ibv/LDAP-Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParseErr.pas
215 lines (196 loc) · 5.29 KB
/
ParseErr.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
{ LDAPAdmin - ParseErr.pas
* Copyright (C) 2012 Tihomir Karlovic
*
* Author: Tihomir Karlovic
*
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
}
unit ParseErr;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
{$IFnDEF FPC}
Windows,
{$ELSE}
LCLIntf, LCLType,
{$ENDIF}
SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TParseErrDlg = class(TForm)
Bevel1: TBevel;
btnClose: TButton;
Label2: TLabel;
SrcMemo: TMemo;
Image1: TImage;
Label1: TLabel;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormActivate(Sender: TObject);
private
fLine: Integer;
fPosition: Integer;
fIdentifier: string;
procedure HighlightText;
end;
procedure ParseError(AType: TMsgDlgType; AOwner: TComponent; const FileName, Err1, Err2, Code, Identifier: string; LineNr, Pos: Integer);
implementation
uses
{$IFnDEF FPC}
MMSystem,
{$ELSE}
{$ENDIF}
Misc, Constant;
{$R *.dfm}
function CountVisibleLines(const Memo: TMemo): Integer;
Var
OldFont: HFont;
DC: THandle;
TextMetric: TTextMetric;
begin
try
DC := GetDC(Memo.Handle);
try
OldFont := SelectObject(DC, Memo.Font.Handle);
try
GetTextMetrics(DC, TextMetric);
Result := (Memo.ClientRect.Bottom - Memo.ClientRect.Top) div
(TextMetric.tmHeight + TextMetric.tmExternalLeading);
finally
SelectObject(DC, OldFont);
end;
finally
ReleaseDC(Memo.Handle, DC);
end;
except
Result := 1;
end;
end;
procedure TParseErrDlg.HighlightText;
var
i: Integer;
function SelectIdentifier: Boolean;
begin
Result := false;
if fIdentifier <> '' then with SrcMemo do
begin
i := Pos(fIdentifier, Lines[fLine]);
if i > 0 then
begin
{$ifdef windows}
SelStart := Perform(EM_LINEINDEX, fLine, 0) + i - 1;
{$else}
SelStart := CaretPos.Y + i - 1;
{$endif}
Result := true;
end;
end;
end;
begin
with SrcMemo do
begin
if not SelectIdentifier then
{$ifdef windows}
SelStart := Perform(EM_LINEINDEX, fLine, 0) + fPosition;
SendMessage(Handle, EM_SCROLLCARET, 0,0);
{$else}
SelStart := CaretPos.Y + fPosition;
//---SendMessage(Handle, EM_SCROLLCARET, 0,0);
{$endif}
i := CountVisibleLines(SrcMemo) - 3;
if CaretPos.Y < i then
Exit;
try
LockControl(SrcMemo, true);
while i > 0 do
begin
{$ifdef windows}
Perform(EM_SCROLL, SB_LINEDOWN, 0);
{$else}
//---
{$endif}
dec(i);
end;
finally
LockControl(SrcMemo, false);
end;
end;
end;
procedure ParseError(AType: TMsgDlgType; AOwner: TComponent; const FileName, Err1, Err2, Code, Identifier: string; LineNr, Pos: Integer);
var
typeMsg: string;
begin
with TParseErrDlg.Create(AOwner) do
try
with Image1.Picture.Icon do
case AType of
mtError: begin
typeMsg := cError;
{$ifdef windows}
Handle := LoadIcon(0, IDI_ERROR);
{$else}
{$endif}
end;
mtWarning: begin
typeMsg := cWarning;
{$ifdef windows}
Handle := LoadIcon(0, IDI_WARNING);
{$else}
{$endif}
end;
mtInformation: begin
typeMsg := cInformation;
{$ifdef windows}
Handle := LoadIcon(0, IDI_INFORMATION);
{$else}
{$endif}
end;
else
typeMsg := '';
end;
Label1.Caption := Format('(%s) %2s (Line %d): %3:s', [typeMsg, FileName, LineNr + 1, Err1]);
if Err2 = '' then
begin
Label1.Top := Bevel1.Top + (Bevel1.Height - Label1.Height) div 2;
end
else
Label2.Caption := Err2;
SrcMemo.Text := Code;
fLine := LineNr;
fPosition := Pos;
fIdentifier := Identifier;
ShowModal;
except
Free;
raise;
end;
end;
procedure TParseErrDlg.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TParseErrDlg.FormActivate(Sender: TObject);
begin
{$ifdef windows}
PlaySound(PChar('SYSTEMHAND'), 0, SND_ASYNC);
{$else}
{$endif}
//PlaySound(PChar(SND_ALIAS_SYSTEMHAND), 0, SND_ALIAS_ID + SND_ASYNC);
SrcMemo.SetFocus;
HighlightText;
end;
end.