-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUConsoleMessageReceiver.pas
More file actions
261 lines (242 loc) · 7.74 KB
/
Copy pathUConsoleMessageReceiver.pas
File metadata and controls
261 lines (242 loc) · 7.74 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
unit UConsoleMessageReceiver;
interface
uses
Windows, SysUtils, Variants, Classes, ActiveX, StdCtrls, SHDocVw, MSHTML, Controls;
type
{$IF NOT DECLARED(IDeveloperConsoleMessageReceiver)}
_DEV_CONSOLE_MESSAGE_LEVEL = TOleEnum;
const
DCML_INFORMATIONAL = $00000000;
DCML_WARNING = $00000001;
DCML_ERROR = $00000002;
DEV_CONSOLE_MESSAGE_LEVEL_Max = $7FFFFFFF;
type
IDeveloperConsoleMessageReceiver = interface(IUnknown)
['{30510808-98B5-11CF-BB82-00AA00BDCE0B}']
function write(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL; messageId: SYSINT;
messageText: PWideChar): HResult; stdcall;
function WriteWithUrl(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL; messageId: SYSINT;
messageText: PWideChar; fileUrl: PWideChar): HResult; stdcall;
function WriteWithUrlAndLine(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL; messageId: SYSINT;
messageText: PWideChar; fileUrl: PWideChar; line: LongWord): HResult; stdcall;
function WriteWithUrlLineAndColumn(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL; messageId: SYSINT;
messageText: PWideChar; fileUrl: PWideChar; line: LongWord; column: LongWord): HResult; stdcall;
end;
{$IFEND}
TConsoleMessageReceiver = class(TCustomMemo, IDeveloperConsoleMessageReceiver)
private
FWebBrowser: TWebBrowser;
FShowInfo: Boolean;
procedure RegisterMessageReceiver(ARegister: Boolean);
function Write(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL; messageId: SYSINT;
messageText: PWideChar): HResult; stdcall;
function WriteWithUrl(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL; messageId: SYSINT;
messageText: PWideChar; fileUrl: PWideChar): HResult; stdcall;
function WriteWithUrlAndLine(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL; messageId: SYSINT;
messageText: PWideChar; fileUrl: PWideChar; line: LongWord): HResult; stdcall;
function WriteWithUrlLineAndColumn(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL; messageId: SYSINT;
messageText: PWideChar; fileUrl: PWideChar; line: LongWord; column: LongWord): HResult; stdcall;
procedure SetWebBrowser(AWebBrowser: TWebBrowser);
public
constructor Create(AOwner: TComponent); override;
published
property WebBrowser: TWebBrowser read FWebBrowser write SetWebBrowser;
property ShowInfo: Boolean read FShowInfo write FShowInfo default True;
property Align;
property Alignment;
property Anchors;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
property BiDiMode;
property BorderStyle;
property Color;
property Constraints;
property Ctl3D;
property DoubleBuffered;
property Enabled;
property Font;
property HideSelection;
property ImeMode;
property ImeName;
property OEMConvert;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentDoubleBuffered;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ScrollBars default ssVertical;
property ShowHint;
property TabOrder;
property TabStop;
property Touch;
property Visible;
property WantReturns;
property WantTabs;
property WordWrap;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGesture;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseActivate;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
procedure Register;
implementation
procedure Register;
begin
Classes.RegisterComponents('Internet', [TConsoleMessageReceiver]);
end;
{TConsoleMessageReceiver}
constructor TConsoleMessageReceiver.Create(AOwner: TComponent);
begin
inherited;
Self.FShowInfo := True;
Self.ScrollBars := ssVertical;
Self.ReadOnly := True;
Self.ParentFont := False;
Self.Font.Name := 'Courier';
end;
procedure TConsoleMessageReceiver.RegisterMessageReceiver(ARegister: Boolean);
const
IDM_ADDCONSOLEMESSAGERECEIVER = 3800;
IDM_REMOVECONSOLEMESSAGERECEIVER = 3801;
CGID_MSHTML: TGUID = '{DE4BA900-59CA-11CF-9592-444553540000}';
var
Comm: IOleCommandTarget;
Action: Cardinal;
OutVar: OleVariant;
begin
if csDesigning in ComponentState then
Exit;
if ARegister then
Action := IDM_ADDCONSOLEMESSAGERECEIVER
else
Action := IDM_REMOVECONSOLEMESSAGERECEIVER;
if Assigned(Self.FWebBrowser) then
begin
OutVar := EmptyParam;
if not Assigned(Self.FWebBrowser.Document) then
Self.FWebBrowser.Navigate('about:blank');
if Supports(Self.FWebBrowser.Document, IOleCommandTarget, Comm) then
Comm.Exec(@CGID_MSHTML, Action, OLECMDEXECOPT_DODEFAULT, IDeveloperConsoleMessageReceiver(Self), OutVar);
end;
end;
procedure TConsoleMessageReceiver.SetWebBrowser(AWebBrowser: TWebBrowser);
begin
if Self.FWebBrowser <> AWebBrowser then
begin
Self.Lines.Clear;
RegisterMessageReceiver(False);
Self.FWebBrowser := AWebBrowser;
RegisterMessageReceiver(True);
end;
end;
function TConsoleMessageReceiver.Write(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL; messageId: SYSINT;
messageText: PWideChar): HResult;
const
MSG_MODEL = '%s'#9'Code %d - %s';
var
LevelType: String;
begin
Result := S_OK;
case level of
DCML_INFORMATIONAL:
begin
if not Self.FShowInfo then
Exit;
LevelType := 'INFO';
end;
DCML_WARNING:
LevelType := 'WARN';
DCML_ERROR:
LevelType := 'ERROR';
end;
Self.Lines.Add(Format(MSG_MODEL, [LevelType, messageId, String(messageText)]));
end;
function TConsoleMessageReceiver.WriteWithUrl(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL; messageId: SYSINT;
messageText, fileUrl: PWideChar): HResult;
const
MSG_MODEL = '%s'#9'Code %d - %s'#13#10#9'> at %s';
var
LevelType: String;
begin
Result := S_OK;
case level of
DCML_INFORMATIONAL:
begin
if not Self.FShowInfo then
Exit;
LevelType := 'INFO';
end;
DCML_WARNING:
LevelType := 'WARN';
DCML_ERROR:
LevelType := 'ERROR';
end;
Self.Lines.Add(Format(MSG_MODEL, [LevelType, messageId, String(messageText), String(fileUrl)]));
end;
function TConsoleMessageReceiver.WriteWithUrlAndLine(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL;
messageId: SYSINT; messageText, fileUrl: PWideChar; line: LongWord): HResult;
const
MSG_MODEL = '%s'#9'Code %d - %s'#13#10#9'> at %s'#13#10#9'> in line %d';
var
LevelType: String;
begin
Result := S_OK;
case level of
DCML_INFORMATIONAL:
begin
if not Self.FShowInfo then
Exit;
LevelType := 'INFO';
end;
DCML_WARNING:
LevelType := 'WARN';
DCML_ERROR:
LevelType := 'ERROR';
end;
Self.Lines.Add(Format(MSG_MODEL, [LevelType, messageId, String(messageText), String(fileUrl), line]));
end;
function TConsoleMessageReceiver.WriteWithUrlLineAndColumn(source: PWideChar; level: _DEV_CONSOLE_MESSAGE_LEVEL;
messageId: SYSINT; messageText, fileUrl: PWideChar; line, column: LongWord): HResult;
const
MSG_MODEL = '%s'#9'Code %d - %s'#13#10#9'> at %s'#13#10#9'> in line %d, column %d';
var
LevelType: String;
begin
Result := S_OK;
case level of
DCML_INFORMATIONAL:
begin
if not Self.FShowInfo then
Exit;
LevelType := 'INFO';
end;
DCML_WARNING:
LevelType := 'WARN';
DCML_ERROR:
LevelType := 'ERROR';
end;
Self.Lines.Add(Format(MSG_MODEL, [LevelType, messageId, String(messageText), String(fileUrl), line, column]));
end;
end.