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 create a Treeview with Keys from the Registry 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
28-Sep-03
Category
Win API
Language
Delphi 3.x
Views
133
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler 

Anyone have any sample code on how to load a TreeView with registry keys, i  want 
to load the
KEY_CURRENT_USER\\Software key, and i want all the subkeys  to load in the treeview 
too. 

Answer:

1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7     StdCtrls, ComCtrls, Registry;
8   
9   type
10    TForm1 = class(TForm)
11      TreeView1: TTreeView;
12      Button1: TButton;
13      procedure Button1Click(Sender: TObject);
14    private
15  
16    public
17  
18      procedure FillRegBranch(rootkey: hkey; parentkey: string; ParentNode: 
19  TTreeNode);
20    end;
21  
22  var
23    Form1: TForm1;
24  
25  implementation
26  
27  {$R *.DFM}
28  
29  procedure TForm1.Button1Click(Sender: TObject);
30  var
31    Node: TTreeNode;
32  begin
33    TreeView1.Items.Clear;
34    TreeView1.Items.BeginUpdate;
35    Node := TreeView1.Items.AddChild(nil, 'Borland');
36    FillRegBranch(HKEY_Local_Machine, 'Software\Borland', Node);
37    TreeView1.Items.EndUpdate;
38  end;
39  
40  procedure tForm1.FillRegBranch(rootkey: hkey; parentkey: string; ParentNode:
41    TTreeNode);
42  var
43    Cnt: Integer;
44    StList: TStrings;
45    Node: tTreeNode;
46    Registry: TRegistry;
47  begin
48    Registry := TRegistry.Create;
49    try
50      Registry.RootKey := rootkey;
51      if Registry.OpenKey(parentkey, false) then
52      begin
53        StList := tStringlist.Create;
54        try
55          Registry.GetKeyNames(StList);
56          for Cnt := 0 to StList.count - 1 do
57          begin
58            Node := TreeView1.Items.addChild(ParentNode, StList.Strings[cnt]);
59            if Registry.HasSubKeys then
60              FillRegBranch(rootkey, parentkey + '\' + StList.Strings[cnt], node);
61          end;
62        finally
63          StList.Free;
64        end;
65      end;
66    finally
67      Registry.Free;
68    end;
69  end;
70  
71  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