Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to list all app's ctrls & menus in a TTreeView ? Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
07-Oct-02
Category
VCL-Menu
Language
Delphi 6.x
Views
11
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Martin Gamulin

How to list all app's ctrls & menus in a TTreeView?

Answer:

1   uses
2     ComCtrls, Menus, Classes, Forms, Controls, Windows, Messages;
3   
4   function GetControlCaption(Control: TWinControl): ShortString;
5   // Slightly modified version of Twister's Tip
6   //
7   // function GetCaptionAtPoint(pt: TPoint): string;
8   //
9   var
10    TextLength: Integer;
11    Text: PChar;
12  begin
13    if not Boolean(Control.Handle) then
14      Exit;
15  
16    Result := Control.Name; // if Control doesn't have Caption
17    // Control.Name is returned
18  
19    TextLength := SendMessage(Control.Handle, WM_GETTEXTLENGTH, 0, 0);
20    if TextLength 0 then
21    begin
22      GetMem(Text, TextLength + 1);
23      SendMessage(Control.Handle, WM_GETTEXT, TextLength + 1, Integer(Text));
24      Result := Text;
25      FreeMem(Text);
26    end;
27  end;
28  
29  // function GetCaptionAtPoint(pt: TPoint): ShortString;
30  // begin
31  // Result:= GetControlCaption(FindVCLWindow(pt));
32  // end;
33  
34  procedure FindAllMenuItems(AppTree: TTreeView; MenuItem: TMenuItem; Parent:
35    TTreeNode);
36  var
37    loop: Integer;
38    Node: TTreeNode;
39    mItem: TMenuItem;
40    Name: ShortString;
41  begin
42    for loop := 0 to MenuItem.Count - 1 do
43    begin
44      mItem := MenuItem.Items[loop];
45      Name := mItem.Caption;
46      Node := AppTree.Items.AddChildObject(Parent, Name, mItem);
47      if mItem.Count 0 then
48        findAllMenuItems(AppTree, mItem, Node);
49    end;
50  end;
51  
52  procedure FindAllControls(AppTree: TTreeView; Comp: TComponent; Parent: TTreeNode);
53  var
54    Child: TComponent;
55    loop, start, Index: Integer;
56    Name: ShortString;
57    Node, Mnode: TTreeNode;
58  begin
59    start := 0;
60    if Comp is TApplication then
61    begin
62      // Parent:= AppTree.Items.AddObjectFirst(Parent, 'Application', nil);
63      // if you want to see the root ('Application') uncomment
64      start := 1;
65    end;
66  
67    for loop := start to Comp.ComponentCount - 1 do
68    begin
69      Child := Comp.Components[loop];
70      Name := Child.Name;
71  
72      if Child is TControl then
73      begin
74        if Child is TWinControl then
75        begin // does Child have Caption property??
76          Name := GetControlCaption(TWinControl(Child));
77        end;
78        Node := AppTree.Items.AddChildObject(Parent, Name, Child);
79        if Child.ComponentCount 0 then
80          FindAllControls(AppTree, Child, Node);
81      end;
82  
83      if Child is TMenu then
84      begin
85        Node := AppTree.Items.AddChildObject(Parent, Name, Child);
86        for Index := 0 to TMenu(Child).Items.Count - 1 do
87        begin
88          Mnode := AppTree.Items.AddChildObject(Node, 
89  TMenu(Child).Items[Index].Caption,
90            TMenu(Child).Items[Index]);
91          FindAllMenuItems(AppTree, TMenu(Child).Items[Index], Mnode);
92        end;
93      end;
94    end;
95  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC