Board index » delphi » Windows Registry

Windows Registry

Hi Folks,

I am trying to read and write some values in the Windows Registry, but I
just can't!
Whenever I try to open the key HKEY_LOCAL_MACHINE I get an Access Violation
message... But, if I open the HKEY_USERS it doesn't happen... What should I
do to read a value in the following key: \HKEY_LOCAL_MACHINE\SAGN\URL
the name of the key is CadConta (I have created it with RegEdit)... I've
tried to use the following code but I allway got that Acess Violation
Message...

procedure TCadCliente.ReadRegistryValues (FileName : String);
var Reg : TRegistry;
    URL_CadConta : String;
begin
  Reg.Create;
  Reg.OpenKey('HKEY_USERS/SAGN/URL',True)
  URL_CadConta := Reg.ReadString('CadConta');
  Reg.CloseKey;
  Reg.Free;
end;

What should I do about that???????

                                     []s Rafael Guimaraes

 

Re:Windows Registry


You can not call a method of a Object that does not exist yet.

USE

   Reg := TRegistry.Create

NOT

   Reg.Create

On 28 Aug 1997 23:01:35 GMT, "Rafael Guimaraes"

Quote
<rgu...@redegazeta.com.br> wrote:
>Hi Folks,

>I am trying to read and write some values in the Windows Registry, but I
>just can't!
>Whenever I try to open the key HKEY_LOCAL_MACHINE I get an Access Violation
>message... But, if I open the HKEY_USERS it doesn't happen... What should I
>do to read a value in the following key: \HKEY_LOCAL_MACHINE\SAGN\URL
>the name of the key is CadConta (I have created it with RegEdit)... I've
>tried to use the following code but I allway got that Acess Violation
>Message...

>procedure TCadCliente.ReadRegistryValues (FileName : String);
>var Reg : TRegistry;
>    URL_CadConta : String;
>begin
>  Reg.Create;
>  Reg.OpenKey('HKEY_USERS/SAGN/URL',True)
>  URL_CadConta := Reg.ReadString('CadConta');
>  Reg.CloseKey;
>  Reg.Free;
>end;

>What should I do about that???????

>                                     []s Rafael Guimaraes

-----------------------------
Nick Roux
Johannesburg, South Africa
Mailto:Roux_N...@Lilly.Com
-----------------------------

Re:Windows Registry


In article <01bcb406$d6c269c0$5b0ef...@pc3-vix.vix.nutecnet.com.br>
           rgu...@redegazeta.com.br "Rafael Guimaraes" writes:

Use TRegistry.Root, set to HKEY_USERS (No Quotes) then
open the key 'SAGN\URL' and readstring 'CadConta'

Quote
> Hi Folks,

> I am trying to read and write some values in the Windows Registry, but I
> just can't!
> Whenever I try to open the key HKEY_LOCAL_MACHINE I get an Access Violation
> message... But, if I open the HKEY_USERS it doesn't happen... What should I
> do to read a value in the following key: \HKEY_LOCAL_MACHINE\SAGN\URL
> the name of the key is CadConta (I have created it with RegEdit)... I've
> tried to use the following code but I allway got that Acess Violation
> Message...

> procedure TCadCliente.ReadRegistryValues (FileName : String);
> var Reg : TRegistry;
>     URL_CadConta : String;
> begin
>   Reg.Create;
>   Reg.OpenKey('HKEY_USERS/SAGN/URL',True)
>   URL_CadConta := Reg.ReadString('CadConta');
>   Reg.CloseKey;
>   Reg.Free;
> end;

> What should I do about that???????

>                                      []s Rafael Guimaraes

--
Daniel Silverstone (Usually ;)

Look at the farstar Homepages on:
 http://www.farstar.demon.co.uk/

Try out Daniel's TPascal Page & Delphi 2.0 bits at
 http://www.farstar.demon.co.uk/Pascal/index.htm

Mail me & give comments (I know it's sparse ;)
 mailto:WebMas...@farstar.demon.co.uk

Re:Windows Registry


On 28 Aug 1997 23:01:35 GMT, "Rafael Guimaraes"

Quote
<rgu...@redegazeta.com.br> wrote:
>Hi Folks,

>I am trying to read and write some values in the Windows Registry, but I
>just can't!
>Whenever I try to open the key HKEY_LOCAL_MACHINE I get an Access Violation
>message... But, if I open the HKEY_USERS it doesn't happen... What should I
>do to read a value in the following key: \HKEY_LOCAL_MACHINE\SAGN\URL
>the name of the key is CadConta (I have created it with RegEdit)... I've
>tried to use the following code but I allway got that Acess Violation
>Message...

>procedure TCadCliente.ReadRegistryValues (FileName : String);
>var Reg : TRegistry;
>    URL_CadConta : String;
>begin
>  Reg.Create;
>  Reg.OpenKey('HKEY_USERS/SAGN/URL',True)
>  URL_CadConta := Reg.ReadString('CadConta');
>  Reg.CloseKey;
>  Reg.Free;
>end;

procedure blah;
var
  reg : tregistry;
begin
  reg:=tRegistry.create;
  reg.rootkey:=HKEY_LOCAL_MACHINE; //or any of the other root-keys you
see when you load up regedit
  if reg.openkey ('SAGN/URL',false) then begin
  //key exists, read value
    url_cadconta=reg.readstring ('cadconta');
  end else begin
  //key does NOT exist, time for error handling here.
  end;
  reg.free;
end;

Other Threads