florisb
asked on
looping some reg keys
Hi Experts,
consider:
const
registryPath = '\Software\SATL\ProjectX\v iews';
procedure DView.getViews(list : tstrings);
var
MyReg: TRegistry;
begin
list := tstrings.create;
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_CURRENT_USER;
if MyReg.OpenKey(registryPath ,False) then
begin
//here I would like to put the names of all subkeys in list.
end
/// close & free
MyReg.CloseKey;
MyReg.Free;
end;
I checked a component that saves views, it uses a 'workaround'. It stores the number of keys in an entry named count, and names all view-subkeys by a number.
I would like save my views by name and be able to retrieve them. Somebody a solution?
Floris.
consider:
const
registryPath = '\Software\SATL\ProjectX\v
procedure DView.getViews(list : tstrings);
var
MyReg: TRegistry;
begin
list := tstrings.create;
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_CURRENT_USER;
if MyReg.OpenKey(registryPath
begin
//here I would like to put the names of all subkeys in list.
end
/// close & free
MyReg.CloseKey;
MyReg.Free;
end;
I checked a component that saves views, it uses a 'workaround'. It stores the number of keys in an entry named count, and names all view-subkeys by a number.
I would like save my views by name and be able to retrieve them. Somebody a solution?
Floris.
Mike, I agree.
ASKER
He, great! Why didn't I find that one before?
Before I give points, why does the following code give an 'abstract error'?
procedure TForm1.Button1Click(Sender : TObject);
var
MyReg: TRegistry;
list : tstrings;
begin
list := tstrings.create;
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_CURRENT_USER;
if MyReg.OpenKey('Software',F alse) then
begin
MyReg.getKeyNames(list);
end
//do something with list.
end;
Before I give points, why does the following code give an 'abstract error'?
procedure TForm1.Button1Click(Sender
var
MyReg: TRegistry;
list : tstrings;
begin
list := tstrings.create;
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_CURRENT_USER;
if MyReg.OpenKey('Software',F
begin
MyReg.getKeyNames(list);
end
//do something with list.
end;
ASKER
copy-pasted code behind GetKeyNames to own proc. Abstract error on Strings.Clear... ....hmmmm.
procedure TRegistry.GetKeyNames(Stri ngs: TStrings);
var
Len: DWORD;
I: Integer;
Info: TRegKeyInfo;
S: string;
begin
Strings.Clear;
if GetKeyInfo(Info) then
begin
SetString(S, nil, Info.MaxSubKeyLen + 1);
for I := 0 to Info.NumSubKeys - 1 do
begin
Len := Info.MaxSubKeyLen + 1;
RegEnumKeyEx(CurrentKey, I, PChar(S), Len, nil, nil, nil, nil);
Strings.Add(PChar(S));
end;
end;
end;
please help!
procedure TRegistry.GetKeyNames(Stri
var
Len: DWORD;
I: Integer;
Info: TRegKeyInfo;
S: string;
begin
Strings.Clear;
if GetKeyInfo(Info) then
begin
SetString(S, nil, Info.MaxSubKeyLen + 1);
for I := 0 to Info.NumSubKeys - 1 do
begin
Len := Info.MaxSubKeyLen + 1;
RegEnumKeyEx(CurrentKey, I, PChar(S), Len, nil, nil, nil, nil);
Strings.Add(PChar(S));
end;
end;
end;
please help!
ASKER
when I remove the clear and my own create and do Strings.Add(S). It works.......
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ah, yes, don't forget to free List afterwards!
Ciao, Mike
Ciao, Mike
const
registryPath = '\Software\SATL\ProjectX\v iews';
procedure DView.getViews(list : tstrings);
var
MyReg: TRegistry;
begin
list := TStringList.create;
//list := tstrings.create;
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_CURRENT_USER;
if MyReg.OpenKey(registryPath ,False) then
begin
MyReg.GetValueNames(list);
//here I would like to put the names of all subkeys in list.
end;
/// close & free
MyReg.CloseKey;
MyReg.Free;
end;
registryPath = '\Software\SATL\ProjectX\v
procedure DView.getViews(list : tstrings);
var
MyReg: TRegistry;
begin
list := TStringList.create;
//list := tstrings.create;
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_CURRENT_USER;
if MyReg.OpenKey(registryPath
begin
MyReg.GetValueNames(list);
//here I would like to put the names of all subkeys in list.
end;
/// close & free
MyReg.CloseKey;
MyReg.Free;
end;
ASKER
fitims, I'm evaluating Lischke and expect that that comment will help me out.... .....and I do need the keys and not the values!
moment...
moment...
ASKER
Thanks!
AAARGH! Tried it all the time with a tstrings. Know now that that's just a base-class.
fitmits; i see you new here. You posted a correct answer too, but Lischke was first. Perhaps better to post comments, then person who asks can just choose which comment to accept.
Floris.
AAARGH! Tried it all the time with a tstrings. Know now that that's just a base-class.
fitmits; i see you new here. You posted a correct answer too, but Lischke was first. Perhaps better to post comments, then person who asks can just choose which comment to accept.
Floris.
Yep, thank you Floris...
Ciao, Mike
Ciao, Mike
Ciao, Mike