I want to display a tree structure with all the registry data in it (i.e. all subkeys). I did the following Fn to do the same. But I receive information 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;
function call
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;
Please note that I am not getting any error, just this information is incomplete
source share