Solved

looping some reg keys

Posted on 2000-03-24
11
144 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

10 Experts available now in Live!

Get 1:1 Help Now