Solved

OpenKey problem in TRegistry descendant

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 267
Printing problem 2 92
I want to use librsync in my Delphi backup application. 3 49
Wincontrol not (correctly) drawn 15 38
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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