Solved

How to use the function KeyExists ?

Posted on 1998-09-01
5
288 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I've never had great succes with TRegIniFile, so I have always used TRegistry..
0
 

Author Comment

by:nk51
Comment Utility
Thanks, it better works with Tregistry.
Thanks to Edo too.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

13 Experts available now in Live!

Get 1:1 Help Now