Solved

How to use the function KeyExists ?

Posted on 1998-09-01
5
292 Views
Last Modified: 2010-05-18
I have to use the function KeyExists to determinate if a Key
exist in the registry.
I test the function with an existing key but the function doesn't find it.
Why?????

My code:

In the interface of the unit 'fmMain':

const
   //Registry
   Cle     : String = 'Software\ANCV\Commande cheques vacance';    //sous HKEY_CURRENT_USER

The procedure using the function KeyExists:

procedure TfmMain.FormCreate(Sender: TObject);
var index              : integer;
    regHKeyCurrentUser : TRegIniFile;
begin

  regHKeyCurrentUser:=TRegIniFile.Create('HKEY_CURRENT_USER');
  if not RegHKeyCurrentUser.KeyExists(cle)
  then
    begin

The key cle exist in the registry but KeyExists return false.What's the problem ?
0
Comment
Question by:nk51
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
BlackMan earned 50 total points
ID: 1338376
Use TRegistry instead. Here's an example:

  With TRegistry.Create Do
  Begin
    RootKey := HKEY_CURRENT_USER;
    If KeyExists('SOFTWARE\Borland\DBD\7.0') Then
      ShowMessage('Key Found')
    Else
      ShowMessage('Key not found');
    Free;
  End;

0
 
LVL 1

Expert Comment

by:Edo082297
ID: 1338377
Salut nk51
  Si tu ne fais pas de changement de win3.1 je suggere d'utiliser TRegistry au lieu de TRegIniFile. De tout facon, je crois que tu as besoin de specifier le path au complet, non?

  (If you are not updating/upgrading from 3.1 I suggest using TRegistry. Anyway, don't you need to specify the whole path?).

Regards,
Edo

0
 
LVL 1

Expert Comment

by:Edo082297
ID: 1338378
Hi Blackman

You and I posted at the same time (I'm not repetitive!). Do you know why his code doesn't work?

nk51: Es-tu ABSOLUMENT certain que le string et le cle correspond?

Edo

0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1338379
I've never had great succes with TRegIniFile, so I have always used TRegistry..
0
 

Author Comment

by:nk51
ID: 1338380
Thanks, it better works with Tregistry.
Thanks to Edo too.
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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 262
indy Tmemory stream non latin charcter issue 2 98
Working with hours 3 46
Dynamically Created Query 3 50
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…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

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