[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How can i enumerate all subfolders of a folder in registry in TreeView.

Posted on 2006-07-11
8
Medium Priority
?
479 Views
Last Modified: 2010-04-05
Hi.

The title is self-explanatory.

I need to list in a treeview the subfolders (not the subfolders of the subfolders  (Depth=1)) of a path in registry.

Example : ( List SubFolders of    HKEY_USERS\Default )
------------------------------------------
HKEY Users
|->Default
      |-> AppEvents
      |-> Console
      |-> Control Panel
      |-> EHelp
      |-> Environment

------------------------------------------

Thanks in advance :)
0
Comment
Question by:CodedK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 10

Accepted Solution

by:
atul_parmar earned 1000 total points
ID: 17080321
Hi, here is how you can do it.

var
  Reg : TRegistry;
  s : TStringList;
begin
  Reg := TRegistry.Create;
  s := TStringList.Create;
  Reg.RootKey := HKEY_USERS;
  Reg.OpenKey('.DEFAULT', False);
  Reg.GetKeyNames(s);
  Memo1.Lines.Assign(s);
  s.Free;
  Reg.Free;
end;
0
 
LVL 28

Assisted Solution

by:2266180
2266180 earned 1000 total points
ID: 17080343
here is how to do it with ttreeview:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls;

type
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses registry;

procedure addthem(key:HKEY; path:string; treeview1:TTreeView);
var t:TTreeNode; r:tregistry; s:tstringlist; i:integer;
begin
  t:=TreeView1.Items.Add(TreeView1.Items.GetFirstNode,path);
  r:=tregistry.Create;
  r.RootKey:=key;
  if r.OpenKey(path,false) and r.HasSubKeys then
  begin
    s:=tstringlist.create;
    r.GetKeyNames(s);
    for i:=1 to s.count do
      TreeView1.Items.Addchild(t,s[i-1]);
    s.free;
  end;
  r.free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  addthem(HKEY_USERS,'.Default',TreeView1);
end;

end.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17080351
Thanks :) ... both

Well if itsnt too much to ask do you know how can i filter those subfolders and list only those...
if they contain a subfolder named "2" ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Expert Comment

by:atul_parmar
ID: 17080381
After retrieving the list to stringlist you can simply check / search into it.
e..g
s.IndexOf('2'); // will return the index if found -1 otherwise.

OR

var
  Reg : TRegistry;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_USERS;
  Reg.OpenKey('.DEFAULT', False);
  if Reg.KeyExists('2') then
     ShowMesasage('The key exists');
  Reg.Free;
end;
0
 
LVL 16

Author Comment

by:CodedK
ID: 17080398
Thanks :)

I'll split the points if you dont mind...
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17080404
That's fine.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17080603
Ciuly how can i insert those values to an allready existing item in the treeview ?
0
 
LVL 28

Expert Comment

by:2266180
ID: 17080628

TreeView1.Items.Addchild(existing node,text)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question