Solved

OpenKey problem in TRegistry descendant

Posted on 2002-05-20
2
687 Views
Last Modified: 2013-11-23
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.
0
Comment
Question by:tomcorcoran
2 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 7021966
Hi,

constructor TMyRegistry.Create;
begin
 inherited Create; // Look here
 RootKey := HKEY_LOCAL_MACHINE;
end;

Regards, Geo
0
 

Author Comment

by:tomcorcoran
ID: 7022148
Geo,

My Gawd, Whooops!!!

Ta mucho :-)

Tom.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 57
TServerSocket - file via sendbuf or Text via sendtext ? 1 67
Tembedded WB animatid gifs not animated on some pcs 2 84
Base1 Encode/Decode 3 82
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

820 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