Solved

Registry Problem

Posted on 2002-04-05
8
171 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View Settings Question 15 116
Run video youtube webbrowse 10 65
JAudiorecorder record freezing the app 29 76
MS Access from Delphi 31 60
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…
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

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