Menu

[r1786]: / trunk / Src / UWBExternal.pas  Maximize  Restore  History

Download this file

262 lines (233 with data), 6.4 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
{
* UWBExternal.pas
*
* COM object that extends the "external" object accessible from JavaScript in a
* browser control and notifies application of events triggered via JavaScript
* calls to the external object's methods.
*
* $Rev$
* $Date$
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is UWBExternal.pas
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2005-2011 Peter
* Johnson. All Rights Reserved.
*
* Contributor(s)
* NONE
*
* ***** END LICENSE BLOCK *****
}
unit UWBExternal;
interface
uses
// Delphi
ComObj, ActiveX,
// Auto-generated project unit
IntfExternalObj, // derived indirectly from ExternalObj.idl
// Project
IntfNotifier;
type
{
TWBExternal:
COM object that extends the "external" object accessible from JavaScript in
a web browser and notifies application of events triggered via JavaScript
calls to the external object's methods. Uses notification object to pass
events to application.
}
TWBExternal = class(TAutoIntfObject,
IWBExternal7, // browser external object's methods
ISetNotifier // sets object used to notify app of events
)
strict private
fNotifier: INotifier; // Notifies application of events triggered by user
procedure HandleException;
{Gets application to handle current exception.
}
protected // do not make strict
{ IWBExternal7: defined in type library }
procedure UpdateDbase; safecall;
{Updates database from internet.
}
procedure DisplaySnippet(const SnippetName: WideString;
UserDefined: WordBool); safecall;
{Displays a named snippet.
@param SnippetName [in] Name of snippet to display.
@param UserDefined [in] Whether snippet is user defined.
}
procedure CompileSnippet; safecall;
{Compiles the current snippet via notifier.
}
procedure ShowHint(const Hint: WideString); safecall;
{Displays a hint.
@param Hint [in] Hint to be displayed.
}
procedure ConfigCompilers; safecall;
{Displays the Configure Compilers dialog box.
}
procedure EditSnippet(const SnippetName: WideString); safecall;
{Edits a named snippet.
@param SnippetName [in] Name of snippet to be edited. Must be a user
defined snippet.
}
procedure Donate; safecall;
{Displays the Donate dialog box.
}
procedure DisplayCategory(const CatID: WideString); safecall;
{Displays a category.
@param CatID [in] ID of category to display.
}
{ ISetNotifier }
procedure SetNotifier(const Notifier: INotifier);
{Records the notifier object that is called in response to user input.
@param Notifier [in] Notifier object.
}
public
constructor Create;
{Class constructor. Sets up object using embedded type library.
}
end;
implementation
uses
// Delphi
Forms,
// Project
UAppInfo;
{ TWBExternal }
procedure TWBExternal.CompileSnippet;
{Compiles the current snippet.
}
begin
try
if Assigned(fNotifier) then
fNotifier.CompileSnippet;
except
HandleException;
end;
end;
procedure TWBExternal.ConfigCompilers;
{Displays the Configure Compilers dialog box.
}
begin
try
if Assigned(fNotifier) then
fNotifier.ConfigCompilers;
except
HandleException;
end;
end;
constructor TWBExternal.Create;
{Class constructor. Sets up object using embedded type library.
}
var
TypeLib: ITypeLib; // type library
ExeName: WideString; // name of this executable file
begin
// Get type library info from exe file
ExeName := TAppInfo.AppExeFilePath;
OleCheck(LoadTypeLib(PWideChar(ExeName), TypeLib));
// Create the object using type library
inherited Create(TypeLib, IWBExternal7);
end;
procedure TWBExternal.DisplayCategory(const CatID: WideString);
{Displays a category.
@param CatID [in] ID of category to display.
}
begin
try
if Assigned(fNotifier) then
fNotifier.DisplayCategory(CatID);
except
HandleException;
end;
end;
procedure TWBExternal.DisplaySnippet(const SnippetName: WideString;
UserDefined: WordBool);
{Displays a named snippet.
@param SnippetName [in] Name of snippet to display.
@param UserDefined [in] Whether snippet is user defined.
}
begin
try
if Assigned(fNotifier) then
fNotifier.DisplaySnippet(SnippetName, UserDefined);
except
HandleException;
end;
end;
procedure TWBExternal.Donate;
{Displays the Donate dialog box.
}
begin
try
if Assigned(fNotifier) then
fNotifier.Donate;
except
HandleException;
end;
end;
procedure TWBExternal.EditSnippet(const SnippetName: WideString);
{Edits a named snippet.
@param SnippetName [in] Name of snippet to be edited. Must be a user defined
snippet.
}
begin
try
if Assigned(fNotifier) then
fNotifier.EditSnippet(SnippetName);
except
HandleException;
end;
end;
procedure TWBExternal.HandleException;
{Gets application to handle current exception.
}
begin
Application.HandleException(ExceptObject);
end;
procedure TWBExternal.SetNotifier(const Notifier: INotifier);
{Records the notifier object that is called in response to user input.
@param Notifier [in] Notifier object.
}
begin
fNotifier := Notifier;
end;
procedure TWBExternal.ShowHint(const Hint: WideString);
{Displays a hint.
@param Hint [in] Hint to be displayed.
}
begin
try
if Assigned(fNotifier) then
fNotifier.ShowHint(Hint);
except
HandleException;
end;
end;
procedure TWBExternal.UpdateDbase;
{Updates database from internet.
}
begin
try
if Assigned(fNotifier) then
fNotifier.UpdateDbase;
except
HandleException;
end;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.