Solved

OpenKey problem in TRegistry descendant

Posted on 2002-05-20
2
690 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

617 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