Solved

looping some reg keys

Posted on 2000-03-24
11
145 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now