Solved

looping some reg keys

Posted on 2000-03-24
11
147 Views
Last Modified: 2010-05-18
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.



0
Comment
Question by:florisb
11 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2653169
What about TRegistry.GetKeyNames?

Ciao, Mike
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2653211
Mike, I agree.
0
 
LVL 2

Author Comment

by:florisb
ID: 2653466
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;
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 2

Author Comment

by:florisb
ID: 2653474
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!
0
 
LVL 2

Author Comment

by:florisb
ID: 2653499
when I remove the clear and my own create and do Strings.Add(S). It works.......


0
 
LVL 10

Accepted Solution

by:
Lischke earned 50 total points
ID: 2653592
Floris you made a small mistake. You cannot create a TStrings class as this is only defining some abstract methods and has no storage handling. You need to use the next descentant TStringList instead. This actually implements the methods defined in TStrings. Your code must then look so:

procedure TForm1.Button1Click(Sender: TObject);
var
  MyReg: TRegistry;
  List : TStringList;
begin
  List := TStringList.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;

Ciao, Mike
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2653598
Ah, yes, don't forget to free List afterwards!

Ciao, Mike
0
 

Expert Comment

by:fitims
ID: 2653673
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;
0
 
LVL 2

Author Comment

by:florisb
ID: 2653725
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...
0
 
LVL 2

Author Comment

by:florisb
ID: 2653805
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.


0
 
LVL 10

Expert Comment

by:Lischke
ID: 2653914
Yep, thank you Floris...

Ciao, Mike
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question