Board index » delphi » registry

registry

Hi
Im a pretty new delphi user and I want to learn more about accessing the
windows system registry from within delphi. My first problem is that I
simply cannot get a value from the registry into a label. Im sure this is a
very simple problem to solve, but I dont know how to.
Please tell me what errors Ive made.
Here is the code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Registry;

type
  TRegistry1 = class(TRegistry)
  end;
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
function GetRegKey(const WantedPath, WantedKey : string) : string;
var Registry:TRegistry;
begin
result:='';
Registry:=TRegistry.Create;
try
Registry.RootKey:=HKEY_CURRENT_USER;
result:=Registry.ReadString(WantedKey);
finally
TRegistry.Free;
end;
end;
begin
  label1.caption:=GetRegKey('ControlPanel\Desktop','Wallpaper');
end;

end.

Thanks for any help!

 

Re:registry


Johan,

Create a routine with the following:

procedure ReadARegValue;
var
  rgReg: TRegistry;
begin
rgReg := TRegistry.Create;
try
   with rgReg do
      begin
        RootKey := HKEY_CURRENT_USER;
       if OpenKey('YourKey', False) then
         begin
             if ValueExists('YourValue') then
                Label1.Caption := ReadString('YourValue');

            CloseKey;
         end;
      end;
finally
    rgReg.Free;
end;

Something like this should do it.

Sincerely,

Fred Jansma.

Quote
Johan Lundahl wrote in message ...
>Hi
>Im a pretty new delphi user and I want to learn more about accessing the
>windows system registry from within delphi. My first problem is that I
>simply cannot get a value from the registry into a label. Im sure this is
a
>very simple problem to solve, but I dont know how to.
>Please tell me what errors Ive made.
>Here is the code:

>unit Unit1;

>interface

Other Threads