Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6789201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:34:31+00:00 2026-05-26T17:34:31+00:00

I want to display a treeview with all the registry information in it (

  • 0

I want to display a treeview with all the registry information in it ( i.e all the subkeys ). I have put together the following Fn to do the same. But i am getting the info of only one Key, not all. What is missing in my code ?

 function TForm1.DisplayKeys(TreeNode : TTreeNode;KeyToSearch:String):String;
 var
  i: Integer;
  RootKey : Integer;
  NewTreeNode : TTreeNode;
  str : TStringList;

 // str2: TStringList;
 begin
   i:=0;

   if reg.OpenKey(KeyToSearch,False) then
   begin
   str:=nil;
   str:=TStringList.create;
   reg.GetKeyNames(str);
   //For all SubKeys
   for i:=0 to str.Count-1 do
   begin
      NewTreeNode:=TreeView1.Items.AddChild(TreeNode, Str.Strings[i]);
      if reg.HasSubKeys then
      begin
        DisplayKeys(NewTreeNode,Str.Strings[i]);
      end;
   end;
 end;

the call to the Function is

  procedure TForm1.FormCreate(Sender: TObject);
  begin
     reg:=nil;
    reg:=TRegistry.create;
    str2:=nil;
    str2:=TStringList.create;
   reg.RootKey:=HKEY_CURRENT_CONFIG;
   TreeView1.Items.BeginUpdate; //prevents screen repaint every time node is added
      DisplayKeys(nil,''); // call to fn here
   TreeView1.Items.EndUpdate; // Nodes now have valid indexes
 end;

Note that i am not getting any error, just that info is incomplete

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:34:32+00:00Added an answer on May 26, 2026 at 5:34 pm

    Some problems:

    1. You are using OpenKey which attempts to open the key with write access. Instead you should use OpenKeyReadOnly. If you really do mean to write to those keys then you will have to run elevated as an administrator.
    2. You are failing to close the keys once you have finished with them.

    More seriously, your use of relative registry keys is not sufficient. I believe you will need to pass around the full path to the key. I wrote a little demo console app to show what I mean:

    program RegistryEnumerator;
    
    {$APPTYPE CONSOLE}
    
    uses
      Classes, Windows, Registry;
    
    var
      Registry: TRegistry;
    
    procedure DisplayKeys(const Key: string; const Depth: Integer);
    var
      i: Integer;
      SubKeys: TStringList;
    begin
      if Registry.OpenKeyReadOnly(Key) then begin
        Try
          SubKeys := TStringList.Create;
          Try
            Registry.GetKeyNames(SubKeys);
            for i := 0 to SubKeys.Count-1 do begin
              Writeln(StringOfChar(' ', Depth*2) + SubKeys[i]);
              DisplayKeys(Key + '\' + SubKeys[i], Depth+1);
            end;
          Finally
            SubKeys.Free;
          End;
        Finally
          Registry.CloseKey;
        End;
      end;
    end;
    
    begin
      Registry := TRegistry.Create;
      Try
        Registry.RootKey := HKEY_CURRENT_CONFIG;
        DisplayKeys('', 0);
        Readln;
      Finally
        Registry.Free;
      End;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
I have a problem with my datatable, I want display the information of a
i have a TreeView in my application . I want to display the nodes
I use the following code to display xml as a treeview. Now I want
I have a simple quiz application and I want display a nice timer /
I want to display data with level of detail, so i use a TreeView,
I have at treeview TextBox, and I want convert my Enum: <TextBlock TextAlignment=Justify VerticalAlignment=Center
So i got this treeview where i want to display some people with as
Ok, I have a treeview which I am using to display a number of
I have created 3 partial classes and i want all of them to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.