Solved

How to use the function KeyExists ?

Posted on 1998-09-01
5
294 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

773 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