-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit1.pas
368 lines (318 loc) · 10.2 KB
/
unit1.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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, PairSplitter, ComCtrls, Menus, Dialogs,
ActnList, StdCtrls, ExtCtrls;
type
TExtendedClassInfo = record
ClassType: TClass;
PackageName: string;
end;
PExtendedClassInfo = ^TExtendedClassInfo;
type
{ TForm1 }
TForm1 = class(TForm)
AboutAction: TAction;
ClassTreeView: TTreeView;
LicenseAction: TAction;
FindAction: TAction;
ActionList1: TActionList;
FindDialog: TFindDialog;
MainMenu1: TMainMenu;
MenuItem1: TMenuItem;
MenuItem10: TMenuItem;
MenuItem11: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
MenuItem5: TMenuItem;
MenuItem6: TMenuItem;
MenuItem7: TMenuItem;
MenuItem8: TMenuItem;
MenuItem9: TMenuItem;
PageControl1: TPageControl;
InheritanceSheet: TTabSheet;
PairSplitter1: TPairSplitter;
PairSplitter2: TPairSplitter;
PairSplitterSide1: TPairSplitterSide;
PairSplitterSide2: TPairSplitterSide;
PairSplitterSide3: TPairSplitterSide;
PairSplitterSide4: TPairSplitterSide;
StaticText1: TStaticText;
StaticText2: TStaticText;
PackageSheet: TTabSheet;
PackageTreeView: TTreeView;
procedure AboutActionExecute(Sender: TObject);
procedure FindActionExecute(Sender: TObject);
procedure FindDialogFind(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure LicenseActionExecute(Sender: TObject);
procedure ClassTreeViewSelectionChanged(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
private
public
procedure BuildPackageTree;
function GetPackageName(AClassNode: TTreeNode): string;
function GetUnitName(AClassNode: TTreeNode): string;
procedure SetPackageName(AClassNode: TTreeNode; AValue: string);
function FindClassNode(AClass: TClass): TTreeNode;
function FindPackageNode(AName: string): TTreeNode;
function FindUnitNode(APackageNode: TTreeNode; AUnitName: string): TTreeNode;
procedure AddClass(AClass: TClass; APackageName: string);
procedure FixPackagesInClassNodes;
procedure FreeData(ATreeView: TTreeView);
end;
var
Form1: TForm1;
implementation
uses About, GraphType, LCLIntf,
{ Units declaring the classes to explore }
BinPropStorage, ChipTemp, {DCF77,} DaemonApp, DOM, DrawnControl, DTV, DynArray, EvMsg,
FIFORAM, GPIO, LangMenu,
LEDView, MasterFm,
NewtonsMethod, PathView, PresEdit, Retain, RetroClock, SinusGenerator,
SlaveSelDlg, SlvSelFm, StreamBase, Universe;
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
{ Package Computer }
AddClass(TChipTempSensor, 'Computer');
AddClass(TTripPoint, 'Computer');
AddClass(TTripPointDescriptions, 'Computer');
AddClass(TChipTempSensors, 'Computer');
AddClass(TLEDView, 'Computer');
AddClass(TRetainData, 'Computer');
AddClass(TSinusGenerator, 'Computer');
{ Package FCL }
AddClass(TCustomDaemonApplication, 'FCL');
AddClass(TDOMNode, 'FCL');
{ Package HMI }
AddClass(TRetroClock, 'HMI');
AddClass(TClockScaleLines, 'HMI');
AddClass(TClockScale, 'HMI');
AddClass(TClock, 'HMI');
AddClass(TLine, 'HMI');
AddClass(TRotativePointer, 'HMI');
AddClass(TWSRectangle, 'HMI');
AddClass(TCircle, 'HMI');
{ Package LCL }
AddClass(TApplication, 'LCL');
{ Package LCLPatch }
AddClass(TLanguageMenu, 'LCLPatch');
AddClass(TMasterForm, 'LCLPatch');
AddClass(TSlaveFormCaptions, 'LCLPatch');
AddClass(TSlaveSelDlg, 'LCLPatch');
AddClass(TSlaveSelForm, 'LCLPatch');
{ Package Newton }
AddClass(TNewtonsMethod, 'Newton');
{ Package Nick }
AddClass(TDetailledTreeView, 'Nick');
AddClass(TPathTreeView, 'Nick');
AddClass(TPresentationPage, 'Nick');
AddClass(TPresentationEditor, 'Nick');
AddClass(TPresentation, 'Nick');
AddClass(TMiniPageView, 'Nick');
{ Package Raspi }
AddClass(TBinaryInput, 'Raspi');
AddClass(TBinaryOutput, 'Raspi');
AddClass(TEdgeDrivenInput, 'Raspi');
AddClass(TGPIOPort, 'Raspi');
{ Package RTL }
AddClass(TObject, 'RTL');
AddClass(TDataModule, 'RTL');
{ Package RTLPatch }
AddClass(TInt32Array, 'RTLPatch');
AddClass(TQWordArray, 'RTLPatch');
AddClass(TByteBoolArray, 'RTLPatch');
AddClass(TInt32Matrix, 'RTLPatch');
{ Package Streams }
AddClass(TAppPropStorage, 'Streams');
AddClass(TFIFORAM, 'Streams');
AddClass(TRegisteredComponentReader, 'Streams');
AddClass(TStreamableClasses, 'Streams');
{ Package Threads }
AddClass(TMessageGenerator, 'Threads');
{ Package World}
AddClass(TUniverse, 'World');
FixPackagesInClassNodes;
ClassTreeView.AlphaSort;
ClassTreeView.FullExpand;
BuildPackageTree;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeData(ClassTreeView);
{FreeData(PackageTreeView) Zeiger auf Daten in ClassTreeView}
end;
procedure TForm1.LicenseActionExecute(Sender: TObject);
var
FileName: string;
begin
FileName := ExtractfilePath(Application.ExeName) + 'LICENSE.txt';
if not OpenDocument(FileName) then
ShowMessageFmt('"%s" nicht gefunden', [FileName]);
end;
procedure TForm1.FindDialogFind(Sender: TObject);
var Node: TTreeNode;
begin
Node := ClassTreeView.Items.FindNodeWithText((Sender as TFindDialog).FindText);
if Node <> nil then begin
Node.Selected := True;
(Sender as TFindDialog).CloseDialog;
end
else ShowMessageFmt('Klasse "%s" nicht gefunden', [(Sender as TFindDialog).FindText])
end;
procedure TForm1.FindActionExecute(Sender: TObject);
begin
FindDialog.Execute
end;
procedure TForm1.AboutActionExecute(Sender: TObject);
begin
AboutBox.ShowModal
end;
procedure TForm1.ClassTreeViewSelectionChanged(Sender: TObject);
begin
StaticText1.Caption := Format('Unit %s', [PExtendedClassInfo((Sender as TTreeView).Selected.Data)^.ClassType.UnitName]);
StaticText2.Caption := Format('Package %s', [PExtendedClassInfo((Sender as TTreeView).Selected.Data)^.PackageName]);
end;
procedure TForm1.PageControl1Change(Sender: TObject);
begin
end;
procedure TForm1.BuildPackageTree;
var
Node, PackageNode, UnitNode: TTreeNode;
PackageName, UnitId: string;
begin
Node := ClassTreeView.Items.GetFirstNode;
while Node <> nil do begin
PackageName := GetPackageName(Node);
PackageNode := FindPackageNode(PackageName);
if PackageNode = nil then PackageNode := PackageTreeView.Items.Add(nil, PackageName);
UnitId := GetUnitName(Node);
UnitNode := FindUnitNode(PackageNode, UnitId);
if UnitNode = nil then UnitNode := PackageTreeView.Items.AddChild(PackageNode, UnitId);
PackageTreeView.Items.AddChildObject(UnitNode, Node.Text, Node.Data);
Node := Node.GetNext;
end;
PackageTreeView.AlphaSort;
PackageTreeView.FullExpand;
end;
function TForm1.GetPackageName(AClassNode: TTreeNode): string;
begin
Result := PExtendedClassInfo(AClassNode.Data)^.PackageName;
end;
function TForm1.GetUnitName(AClassNode: TTreeNode): string;
begin
Result := PExtendedClassInfo(AClassNode.Data)^.ClassType.UnitName;
end;
procedure TForm1.SetPackageName(AClassNode: TTreeNode; AValue: string);
begin
PExtendedClassInfo(AClassNode.Data)^.PackageName := AValue
end;
function TForm1.FindClassNode(AClass: TClass): TTreeNode;
begin
Result := ClassTreeView.Items.GetFirstNode;
while Result <> nil do begin
if PExtendedClassInfo(Result.Data)^.ClassType = AClass then Exit;
Result := Result.GetNext;
end;
end;
function TForm1.FindPackageNode(AName: string): TTreeNode;
begin
Result := PackageTreeView.Items.GetFirstNode;
while Result <> nil do begin
if Result.Text = AName then Exit;
Result := Result.GetNextSibling;
end;
end;
function TForm1.FindUnitNode(APackageNode: TTreeNode; AUnitName: string
): TTreeNode;
begin
Result := APackageNode.GetFirstChild;
while Result <> nil do begin
if Result.Text = AUnitName then Exit;
Result := Result.GetNextSibling;
end;
end;
procedure TForm1.AddClass(AClass: TClass; APackageName: string);
function NewInfo(AClass: TClass; APackageName: string): PExtendedClassInfo;
begin
New(Result);
Result^.ClassType := AClass;
Result^.PackageName := APackageName
end;
var
ParentNode: TTreeNode;
ParentClass: TClass;
Path: TList;
i: Integer;
begin
if AClass = nil then Exit;
if FindClassNode(AClass) <> nil then Exit;
ParentClass := AClass.ClassParent;
if ParentClass = nil then begin
ClassTreeView.Items.AddObject(nil, AClass.ClassName, NewInfo(AClass, APackageName));
Exit
end;
ParentNode := FindClassNode(ParentClass);
Path := TList.Create;
try
while ParentNode = nil do begin
Path.Add(ParentClass);
ParentClass := ParentClass.ClassParent;
if ParentClass = nil then begin
for i := Path.Count - 1 downto 0 do begin
ParentNode := ClassTreeView.Items.AddChildObject(ParentNode, TClass(Path[i]).ClassName, NewInfo(TClass(Path[i]), ''));
end;
ClassTreeView.Items.AddChildObject(ParentNode, AClass.ClassName, NewInfo(AClass, APackageName));
Exit
end;
ParentNode := FindClassNode(ParentClass);
end;
for i := Path.Count - 1 downto 0 do begin
ParentNode := ClassTreeView.Items.AddChildObject(ParentNode, TClass(Path[i]).ClassName, NewInfo(TClass(Path[i]), ''))
end;
ClassTreeView.Items.AddChildObject(ParentNode, AClass.ClassName, NewInfo(AClass, APackageName));
finally
Path.Free
end;
end;
procedure TForm1.FixPackagesInClassNodes;
var Node, SourceNode: TTreeNode;
begin
Node := ClassTreeView.Items.GetFirstNode;
while Node <> nil do begin
if GetPackageName(Node) = '' then begin
SourceNode := ClassTreeView.Items.GetFirstNode;
while SourceNode <> nil do begin
if SourceNode = Node then begin
SourceNode := SourceNode.GetNext;
Continue;
end;
if GetUnitName(SourceNode) = GetUnitName(Node) then
if GetPackageName(SourceNode) <> '' then begin
SetPackageName(Node, GetPackageName(SourceNode));
Break
end;
SourceNode := SourceNode.GetNext;
end;
end;
Node := Node.GetNext;
end;
end;
procedure TForm1.FreeData(ATreeView: TTreeView);
var
Node: TTreeNode;
begin
Node := ATreeView.Items.GetFirstNode;
while Assigned(Node) do begin
if Assigned(Node.Data) then begin
Dispose(PExtendedClassInfo(Node.Data));
Node.Data := nil
end;
Node := Node.GetNext;
end;
end;
end.