?
Solved

Registry Problem

Posted on 2002-04-05
8
Medium Priority
?
174 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
[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
  • 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 100 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Assisted Solution

by:geobul
geobul earned 100 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 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