Link to home
Start Free TrialLog in
Avatar of boardtc
boardtcFlag for Ireland

asked on

OpenKey problem in TRegistry descendant

I have a class which inherits from TRegistry. I create an instance of my class (the Rootkey is set in the contructor) and do an OpenKey which fails.

However I can create an instance of TRegistry, set the RootKey and do the same OpenKey which works.

Does anyon knowe why this is? A sinple code exanple follows.

Thanks, Tom.

unit Unit1;

interface

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

type
  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


  TMyRegistry = class(TRegistry)
  public
    constructor Create;
    procedure Open;
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
  var
    temp : TRegistry;
begin
  temp := TRegistry.Create;
  temp.RootKey := HKEY_LOCAL_MACHINE;
  if temp.OpenKey('Software\DELETE THIS',True) then
    ShowMessage('TRegistry : Opened')  // SHOWS
  else
    ShowMessage('TRegistry : Did not open');
end;

procedure TForm2.Button2Click(Sender: TObject);
  var
    temp : TMyRegistry;
begin
  temp := TMyRegistry.Create;
  temp.Open;
end;

{ TtestRegistry }

constructor TMyRegistry.Create;
begin
  RootKey := HKEY_LOCAL_MACHINE;
end;


procedure TMyRegistry.Open;
begin
  if OpenKey('Software\DELETE THIS',True) then
    ShowMessage('TRegistry : Opened')
  else
    ShowMessage('TRegistry : Did not open'); // SHOWS
end;

end.
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of boardtc

ASKER

Geo,

My Gawd, Whooops!!!

Ta mucho :-)

Tom.