[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

looping some reg keys

Posted on 2000-03-24
11
Medium Priority
?
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 200 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 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