Link to home
Start Free TrialLog in
Avatar of florisb
florisb

asked on

looping some reg keys

Hi Experts,

consider:

const
registryPath = '\Software\SATL\ProjectX\views';

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.



Avatar of Lischke
Lischke

What about TRegistry.GetKeyNames?

Ciao, Mike
Mike, I agree.
Avatar of florisb

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',False) then
  begin
  MyReg.getKeyNames(list);
  end
//do something with list.
end;
Avatar of florisb

ASKER

copy-pasted code behind GetKeyNames to own proc. Abstract error on Strings.Clear... ....hmmmm.

procedure TRegistry.GetKeyNames(Strings: 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!
Avatar of florisb

ASKER

when I remove the clear and my own create and do Strings.Add(S). It works.......


ASKER CERTIFIED SOLUTION
Avatar of Lischke
Lischke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah, yes, don't forget to free List afterwards!

Ciao, Mike
const
registryPath = '\Software\SATL\ProjectX\views';

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;
Avatar of florisb

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...
Avatar of florisb

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.


Yep, thank you Floris...

Ciao, Mike