procedure TForm1.FormCreate(Sender: TObject);
begin
//adds the 4 main Registry keys for user to select to explore the registry.
TreeView1.Items.Add(nil,'HKEY_CLASSES_ROOT\');
TreeView1.Items.Add(nil,'HKEY_CURRENT_USER\');
TreeView1.Items.Add(nil,'HKEY_LOCAL_MACHINE\');
TreeView1.Items.Add(nil,'HKEY_CURRENT_CONFIG\');
end;
procedure TForm1.TreeView1Click(Sender: TObject);
begin
//used to get subkeys of a seleced node to display.
GetSubKeys(TreeView1.Selected);
end;
procedure TForm1.GetSubKeys( tnSub: TTreeNode);
var
slkeys: TStringList; //string list to hold subkeys of main key
i: Integer; //used to incroment trough string list.
tnKey: TTreeNode; //tree node to find parent node
begin
with TRegistry.Create do
try
tnKey:=tnSub;
while tnKey.Level >0 do // loop to find parent
tnkey:=tnKey.Parent; //parent node found
//check to find what Key the parent is from and assign it to the
//registry component to open.
if tnkey.Text ='HKEY_CLASSES_ROOT\' then
RootKey := HKEY_CLASSES_ROOT
else if tnkey.Text ='HKEY_CURRENT_USER\' then
RootKey := HKEY_CURRENT_USER
else if tnkey.Text ='HKEY_LOCAL_MACHINE\' then
RootKey := HKEY_LOCAL_MACHINE
else if tnkey.Text ='HKEY_CURRENT_CONFIG\' then
RootKey := HKEY_CURRENT_CONFIG;
if tnSub.Level=0 then // if parent node is selected then get subkeys
OpenKey( '',false )
else
OpenKey( tnSub.Text,false );//if subnode selected then get subkeys of subnode
slKeys := TStringList.Create;
try
GetKeynames(slkeys); //gets the subkey names of the open parent key.
CloseKey;
TreeView1.Items.EndUpdate;//used to cut down time in display alot of node
for i := 0 to slKeys.Count - 1 do
begin
if tnSub.Level=0 then begin
//add subkeys of main keys to tree node.
TreeView1.items.AddChild(tnSub,slKeys[i]+'\') ;
end
else
//add subkeys of registry to tree node
TreeView1.items.AddChild(tnSub,tnSub.Text+ slKeys[i]+'\')
end;
TreeView1.Items.BeginUpdate;//turn on to display nodes
finally
slkeys.Free
end;
finally
Free;
end;
end;