Board index » delphi » TRegIniFile bug

TRegIniFile bug

Hi,

I'm developing with Delphi v3.02 and I'm virtually certain that I've
found a bug when using the TRegIniFile component.

If the following code is compiled and run without the commented line,
the 'KeyExists' will ALWAYS return 'False':-

var
  RegIni: TRegIniFile;
begin
  RegIni := TRegIniFile.Create('HKEY_LOCAL_MACHINE');
//  RegIni.RootKey := HKEY_LOCAL_MACHINE;
  if (RegIni.KeyExists
      ('System\CurrentControlSet\Services\Class\Modem\0000'))
       <> True then

however, if it is compiled and run with the commented line, it works.

Using the de{*word*81}, setting the editor cursor on the 'KeyExists' line,
Running To Cursor and using Evaluate/Modify to inspect the values of the
'RegIni' Properties gives the following results:-

RegIni property         without line                with line

FileName                'HKEY_LOCAL_MACHINE'        'HKEY_LOCAL_MACHINE'
CurrentKey              '-1055069524'               '0'
CurrentPath             'HKEY_LOCAL_MACHINE'        ''
RootKey                 '-2147483647'               '-2147483646'

The differences in three of the four pairs of values, particularly the
RootKey pair, suggest that the theory behind the TRegIniFile.FileName
property, as set out in the Help, is not working in practice.

For info., I believe that the following is the relevant bit of Help:-

'The FileName passed to a TRegIniFile object becomes a subkey under the
system registrys root key (HKEY_CURRENT_USER by default). What
corresponds to a section in an INI file is treated as a key in the
system registry, and what corresponds to data entries under a section in
an INI file are treated as data values under a key in the system
registry.'

Regards,

Stuart

 

Re:TRegIniFile bug


On Tue, 03 Mar 1998 16:57:44 +0000, Stuart <cashbacs....@{*word*269}.net>
wrote:

Quote
>  RegIni := TRegIniFile.Create('HKEY_LOCAL_MACHINE');
>//  RegIni.RootKey := HKEY_LOCAL_MACHINE;
 ...
>'The FileName passed to a TRegIniFile object becomes a subkey under the
>system registrys root key (HKEY_CURRENT_USER by default). What
>corresponds to a section in an INI file is treated as a key in the
>system registry, and what corresponds to data entries under a section in
>an INI file are treated as data values under a key in the system
>registry.'

I don't think you can ever use the string to specify the root key.
You're looking at the key "HKEY_CURRENT_USER/HKEY_LOCAL_MACHINE",
which isn't what you want.  So I wouldn't call this a bug, just a
misunderstanding of the help file.

Duncan Murdoch

Re:TRegIniFile bug


Hi.

I think TRegIniFile uses for the purpose of saving your own application
settings.

To access the system registries, I recommend to use TRegistry.

-----
var
 Reg:TRegistry;
begin
 Reg:=TRegistry.Create;
 with Reg do
 begin
  try
   RootKey:=HKEY_LOCAL_MACHINE;
   if keyExists('\System\CurrentControlSet\Services\Class\Modem\0000') then
    //Checkbox1.Checked:=True;
  finally
   Free;
  end;
 end;
end;

Quote
>If the following code is compiled and run without the commented line,
>the 'KeyExists' will ALWAYS return 'False':-

>var
>  RegIni: TRegIniFile;
>begin
>  RegIni := TRegIniFile.Create('HKEY_LOCAL_MACHINE');
>//  RegIni.RootKey := HKEY_LOCAL_MACHINE;
>  if (RegIni.KeyExists
>      ('System\CurrentControlSet\Services\Class\Modem\0000'))
>       <> True then

-----
Hiki Takehito

Other Threads