-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
WelcomePageIntf.pas
222 lines (199 loc) · 5.37 KB
/
WelcomePageIntf.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
216
217
218
219
220
221
222
unit WelcomePageIntf;
interface
type
TWindowClosingEvent = procedure (Sender: TObject; CanClose: Boolean; Data: Integer);
IURLModule = interface
['{9D215B02-6073-45DC-B007-1A2DBCE2D693}']
procedure Close;
function GetURL: string; // tested
procedure SetURL(const AURL: string); // tested
procedure SourceActivated;
function GetWindowClosingEvent: TWindowClosingEvent; // WARNING!!! DO NOT CALL!!!
procedure Proc1;
procedure Proc2;
procedure Proc3;
procedure Proc4;
procedure Proc5;
property URL: string read GetURL write SetURL;
end;
IValidateSource = interface
['{ED7F0BEA-DFFC-4048-B9C0-70DC1DE9D031}']
procedure SourceValidated; // function? // partially tested
end;
IDocModule = interface
['{60AE6F18-62AD-4E39-A999-29504CF2632A}']
procedure AddToProject;
function GetFileName: string;
procedure GetIsModified;
function GetModuleName: string;
procedure Save;
procedure Show; // doesn't seem to work properly...
procedure ShowEditor(Visible: Boolean; const Filename: string);
procedure GetProjectCount;
procedure GetProject;
procedure GetActiveProject;
property Filename: string read GetFilename;
property ModuleName: string read GetModuleName;
end;
IUnknown3 = interface
['{15D3FB81-EF27-488E-B2B4-26B59CA89D9D}']
procedure AddNotifier;
procedure AddToInterface;
end;
IUnknown6 = interface
['{9D215B02-6073-45DC-B007-1A2DBCE2D693}']
procedure Proc1;
procedure Proc2;
procedure Proc3;
procedure Proc4;
end;
IUnknown7 = interface
['{9E9C81A0-EDDC-11D1-9504-00608CCBF153}']
procedure GetDocModule;
procedure AddModuleHandler;
procedure RemoveModuleHandler;
end;
IUnknown8 = interface
['{DEF9DC3E-E68A-4341-90C4-426178AED0AA}']
procedure Proc1;
procedure Proc2;
procedure Proc3;
procedure Proc4;
end;
IUnknown11 = interface
['{F9D448F2-50BC-11D1-9FB5-0020AF3D82DA}']
function GetInstance: TObject;
end;
IUnknown12 = interface
['{FFD0A5AF-49CB-4EC2-A658-957146030CEC}']
procedure HasObjects;
end;
type
TGUIDs = array of TGUID;
function GoURL(const URL: string): Boolean;
function GetGUID(const AObject: TObject): TGUIDs; overload;
implementation
uses
ToolsAPI, SysUtils, ActiveX, Clipbrd, Controls;
// From Hallvard
function GetImplementingObject(const I: IInterface): TObject;
const
AddByte = $04244483;
AddLong = $04244481;
type
PAdjustSelfThunk = ^TAdjustSelfThunk;
TAdjustSelfThunk = packed record
case AddInstruction: longint of
AddByte : (AdjustmentByte: shortint);
AddLong : (AdjustmentLong: longint);
end;
PInterfaceMT = ^TInterfaceMT;
TInterfaceMT = packed record
QueryInterfaceThunk: PAdjustSelfThunk;
end;
TInterfaceRef = ^PInterfaceMT;
var
QueryInterfaceThunk: PAdjustSelfThunk;
begin
Result := Pointer(I);
if Assigned(Result) then
try
QueryInterfaceThunk := TInterfaceRef(I)^. QueryInterfaceThunk;
case QueryInterfaceThunk.AddInstruction of
AddByte: Inc(PChar(Result), QueryInterfaceThunk.AdjustmentByte);
AddLong: Inc(PChar(Result), QueryInterfaceThunk.AdjustmentLong);
else
Result := nil;
end;
except
Result := nil;
end;
end;
function GetGUID(const AInterface: IInterface): TGUIDs; overload;
begin
Result := GetGUID(GetImplementingObject(AInterface));
end;
procedure ConvertError(const S: string);
begin
raise EConvertError.Create(S);
end;
function GUIDToString(const GUID: TGUID): string;
var
P: PWideChar;
begin
if not Succeeded(StringFromCLSID(GUID, P)) then
ConvertError('SInvalidGUID');
Result := P;
CoTaskMemFree(P);
end;
function GetGUID(const AObject: TObject): TGUIDs;
var
ClassPtr: TClass;
IntfTable: PInterfaceTable;
ResultI, I: Integer;
pie: PInterfaceEntry;
Text: string;
begin
Result := nil;
ClassPtr := AObject.ClassType;
ResultI := 0;
while ClassPtr <> nil do
begin
IntfTable := ClassPtr.GetInterfaceTable;
if IntfTable <> nil then
begin
SetLength(Result, IntfTable.EntryCount + Length(Result));
for I := 0 to IntfTable.EntryCount-1 do
begin
Result[ResultI] := IntfTable.Entries[I].IID;
Inc(ResultI);
end;
end;
ClassPtr := ClassPtr.ClassParent;
end;
Text := '';
for I := Low(Result) to High(Result) do
Text := Text + '['''+
GuidToString(Result[I])+
''']'#13#10;
Clipboard.AsText := Text;
Result := nil;
end;
function GoURL(const URL: string): Boolean;
var
ModuleServices: IOTAModuleServices;
Module: IOTAModule;
Editor: IOTAEditor;
SourceEditor: IOTASourceEditor;
I: Integer;
Project: IOTAProject;
S: string;
URLModule: IURLModule;
Unknown1: IValidateSource;
DocModule: IDocModule;
Unknown3: IUnknown3;
Unknown6: IUnknown6;
Unknown7: IUnknown7;
Unknown8: IUnknown8;
Unknown9: IValidateSource;
Unknown11: IUnknown11;
Unknown12: IUnknown12;
MS: IOTAMessageServices;
Obj: TObject;
begin
Result := False;
ModuleServices := BorlandIDEServices as IOTAModuleServices;
for I := 0 to ModuleServices.ModuleCount-1 do
begin
Module := ModuleServices.Modules[I];
if Supports(Module, IURLModule, URLModule) then
begin
if Supports(Module, IDocModule, DocModule) then
begin
URLModule.URL := URL;
Result := True;
end;
end;
end;
end;
end.