Solved

Registry Problem

Posted on 2002-04-05
8
169 Views
Last Modified: 2010-04-04
I have A problem with the following code. this code is not retrieving me the data. when i look at the path through regedit i can see the reg values r there. wheather i need to refresh  or what should i do


procedure TForm1.Button1Click(Sender: TObject);
var
  sRegSubKey : string;
  vRegistry : TRegistry;
  Version,databaseNameT : string;

begin
  try
    try
      sRegSubKey := 'Path to the reg file';
      vRegistry := TRegistry.Create;
      vRegistry.RootKey := HKEY_LOCAL_MACHINE;
      {surinscrit la registry si nécessaire, CanCreate=True}
      vRegistry.OpenKey(sRegSubKey, True);
      with vRegistry do
      begin
        Version := ReadString('Version');
        databaseNameT:=ReadString('DatabaseName');
      end; {with}

    finally
     vRegistry.free;
    end;

    Label1.Caption := 'Release '+Version;
    Label2.Caption:='DatbaseName '+databaseNameT;
  except
    On E:Exception do
    begin
      ShowMessage('excep');
    end;
  end;
end;
0
Comment
Question by:jonathan2002
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 4

Expert Comment

by:nestorua
ID: 6922525
HI,jonathan2002,
You are not allowed to create Key as you want.
What you can do is:
sRegSubKey := 'SoftWare\Path to the reg file';
...
or
sRegSubKey := 'SoftWare\Path to the reg file';
...
vRegistry.RootKey := HKEY_CURRENT_USER;
...
And one more remark.
You use the block try-finally-end in not quite proper way.
Sincerely,
Nestorua.
0
 
LVL 4

Expert Comment

by:nestorua
ID: 6922528
Sorry,
In the second way it is:
or
sRegSubKey := 'Path to the reg file';
...
vRegistry.RootKey := HKEY_CURRENT_USER;Sincerely,
Nestorua.
0
 
LVL 1

Accepted Solution

by:
OryxConLara earned 25 total points
ID: 6923533
jonahat2002--

I'll assume that when you wrote "'Path to the reg file'" you meant something like "SOFTWARE\Borland\Borland Shared\DBExpress", and just didn't want to bother us with the details :).

One problem may be that the Version and Databasename keys aren't strings, but some other type. What type of key does Regedit show for these two values of the key? If it's not REG_SZ, then these aren't stored as strings, and we'll have to do something else to extract this info. If you can tell me what kind they are, I think I may be able to help you further.
0
 
LVL 17

Assisted Solution

by:geobul
geobul earned 25 total points
ID: 6923715
Hi,

try:
vRegistry.Access := KEY_READ;
vRegistry.OpenKey(sRegSubKey, false);

perhaps you have 'read only' access to that key.

Regards, Geo
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 2

Expert Comment

by:gallaghe
ID: 6928247
You should first check to see if the key exists, then open it Read-Only if under HKLM i.e.

   if vRegistry.OpenKey(sRegSubKey, False) then
   begin
      ...
   or

   if vRegistry.OpenKeyReadOnly(sRegSubKey) then
   begin
      ...


Also when getting a value use
   if vRegistry.ValueExists(sRegSubKey) then
      Version := ReadString('Version');
      ...

never assume the value exists.
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9002927
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between OryxConLara and gallaghe

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0
 
LVL 17

Expert Comment

by:geobul
ID: 9003078
pnh73,

what new have gallaghe added to this question? There are two possible reasons: either the key is not of string type (pointed out by OryxConLara) or the user has no write access and has to open the key read-only (pointed by me). The original code has try..except block so it's definatelly not necessary to check if the key exists beforehand.

Regards, Geo
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9004732
I will leave a recommendation in the Cleanup topic area that this question is:

Split between OryxConLara and geobul

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Paul (pnh73)
EE Cleanup Volunteer
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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
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.

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

19 Experts available now in Live!

Get 1:1 Help Now