Author: William Gerbert
I am making a program for editing the registry. It will basically be the same as
regedit, but with some added features. What I want to know is how should I go about
reading the registry into my TreeView and ListView components and how do I specify
which icons to use in the tree view? I know you can load files into a list view
using the FindFirst, FindNext and FindClose, but how do you loop through the keys
in the registry?
Answer:
Enumerating registry keys:
1 procedure TForm1.Button1Click(Sender: TObject);
2 var3 indent: Integer;
4 5 procedure EnumAllKeys(hkey: THandle);
6 var7 l: TStringList;
8 n: Integer;
9 begin10 Inc(indent, 2);
11 with TRegistry.Create do12 try13 RootKey := hkey;
14 OpenKey(EmptyStr, false);
15 l := TStringLIst.Create;
16 try17 GetKeynames(l);
18 CloseKey;
19 for n := 0 to l.Count - 1 do20 begin21 memo1.lines.add(StringOfChar(' ', indent) + l[n]);
22 if OpenKey(l[n], false) then23 begin24 EnumAllKeys(CurrentKey);
25 CloseKey;
26 end;
27 end;
28 finally29 l.Free
30 end;
31 finally32 Free;
33 end;
34 Dec(indent, 2);
35 end;
36 begin37 memo1.Clear;
38 memo1.lines.add('Keys under HKEY_CURRENT_USER');
39 indent := 0;
40 EnumAllKEys(HKEY_CURRENT_USER);
41 end;