-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIDEStructureForm.pas
More file actions
190 lines (170 loc) · 4.84 KB
/
Copy pathIDEStructureForm.pas
File metadata and controls
190 lines (170 loc) · 4.84 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
unit IDEStructureForm;
interface
uses
Winapi.Windows, System.Classes, Vcl.Controls, Vcl.StdCtrls, Vcl.Forms,
Vcl.ExtCtrls, Vcl.ComCtrls;
type
TfrmIDEStructure = class(TForm)
Memo: TMemo;
Timer: TTimer;
StatusBar: TStatusBar;
procedure FormShow(Sender: TObject);
procedure TimerTimer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
lastHwnd: THandle;
procedure ShowComponents(path: string; c: TComponent; level: integer);
function GetParentClasses(c: TClass): string;
procedure ShowWindowInfo(pos: TPoint);
public
class procedure Open;
end;
var
frmIDEStructure: TfrmIDEStructure;
procedure GetProperties(obj: TObject; fileName: string);
implementation
{$R *.dfm}
uses Rtti, IOUtils, Generics.Collections, StrUtils, SysUtils, Tabs;
procedure GetProperties(obj: TObject; fileName: string);
var
rttiContext: TRttiContext;
props: TArray<TRttiProperty>;
s: string;
i, n: integer;
begin
rttiContext := TRttiContext.Create;
props := rttiContext.GetType(obj.ClassType).GetProperties;
s := obj.ClassName + ':' + #13#10;
n := 0;
for i := 0 to Length(props) - 1 do
begin
Inc(n);
s := s + props[i].Name + '; ';
if n > 7 then
begin
n := 0;
s := s + #13#10;
end;
end;
TFile.WriteAllText(fileName, s);
end;
function TfrmIDEStructure.GetParentClasses(c: TClass): string;
begin
Result := c.ClassParent.ClassName;
if (c.ClassParent = TComponent) or (c.ClassParent = TControl)
or (c.ClassParent = TWinControl) then
exit;
Result := Result + ':' + GetParentClasses(c.ClassParent);
end;
procedure TfrmIDEStructure.ShowComponents(path: string; c: TComponent;
level: integer);
var
i: integer;
text, s: string;
cs: TDictionary<TComponent, TComponent>;
begin
text := '';
if level > 0 then
text := DupeString('-', level * 2);
text := text + path + ': ' + c.ClassName + ', Name: ' + c.Name
+ ', ClassParents: ' + GetParentClasses(c.ClassType);
if c is TControl then
text := text + ', Caption: ' + TLabel(c).Caption;
if c is TTabSet then
begin
text := text + ', Tabs: ';
for s in TTabSet(c).Tabs.ToStringArray do
text := text + s + '|';
if TTabSet(c).Tabs.Count > 0 then
text := LeftStr(text, Length(text) - 1);
end;
Memo.Lines.Add(text);
cs := TDictionary<TComponent, TComponent>.Create;
try
if c is TWinControl then
for i := 0 to TWinControl(c).ControlCount - 1 do
begin
ShowComponents('Controls[' + IntToStr(i) + ']',
TWinControl(c).Controls[i], level + 1);
cs.Add(TWinControl(c).Controls[i], TWinControl(c).Controls[i]);
end;
for i := 0 to c.ComponentCount - 1 do
if not cs.ContainsKey(c.Components[i]) then
begin
ShowComponents('Components[' + IntToStr(i) + ']',
c.Components[i], level + 1);
cs.Add(c.Components[i], c.Components[i]);
end;
finally
cs.Free;
end;
if level = 0 then
begin
Memo.Lines.Add('*********************************************************');
Memo.Lines.Add('');
end;
end;
procedure TfrmIDEStructure.TimerTimer(Sender: TObject);
var
pos: TPoint;
begin
if Boolean(GetCursorPos(pos)) then
ShowWindowInfo(pos);
end;
procedure TfrmIDEStructure.ShowWindowInfo(pos: TPoint);
var
hwnd: THandle;
control: TWinControl;
name: array [0..254] of char;
begin
hwnd := WindowFromPoint(pos);
if lastHwnd <> hwnd then
begin
StatusBar.Panels[0].Text := 'A window under the cursor... Handle: ' + IntToStr(hwnd);
control := FindControl(hwnd);
if assigned(control) then
begin
StatusBar.Panels[0].Text := StatusBar.Panels[0].Text + '; ClassName: ' + control.ClassName;
if control.Name <> '' then
StatusBar.Panels[0].Text := StatusBar.Panels[0].Text + '; Name: ' + control.Name;
end
else if boolean(GetClassName(hwnd, name, 255)) then
StatusBar.Panels[0].Text := StatusBar.Panels[0].Text + '; ClassName: ' + string(name)
else
StatusBar.Panels[0].Text := StatusBar.Panels[0].Text + '; ClassName: not found';
lastHwnd := hwnd;
end;
end;
procedure TfrmIDEStructure.FormCreate(Sender: TObject);
begin
lastHwnd := 0;
end;
procedure TfrmIDEStructure.FormDestroy(Sender: TObject);
begin
frmIDEStructure := nil;
end;
procedure TfrmIDEStructure.FormShow(Sender: TObject);
var
i: integer;
begin
Screen.Cursor := crHourGlass;
try
for i := 0 to Screen.FormCount - 1 do
ShowComponents('Screen.Forms[' + IntToStr(i) + ']', Screen.Forms[i], 0);
finally
Screen.Cursor := crDefault;
end;
end;
class procedure TfrmIDEStructure.Open;
begin
if not assigned(frmIDEStructure) then
frmIDEStructure := TfrmIDEStructure.Create(Application);
frmIDEStructure.Show;
end;
initialization
frmIDEStructure := nil;
finalization
if assigned(frmIDEStructure) then
frmIDEStructure.Free;
end.