Solved

OpenKey problem in TRegistry descendant

Posted on 2002-05-20
2
683 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now