I don't whether it's just me but this is bizarre.  If I have a class with
TRegistry in it in another unit which is responsible for the life of the
registry object, and then instanitate from my form unit, the saving to the
registry doesn't work.  If I instantiate a TRegistry in my form unit, it
saves the value into the registry.

For example:  This works

{ on click of button or similar }
var
        Reg : TRegistry;
begin
        Reg := TRegistry.Create;
        Reg.RootKey := HKEY_LOCAL_MACHINE;
        Access := KEY_ALL_ACCESS;
        if Reg.OpenKey('Some key structure', True) then begin
                WriteString('Some registry value', 'My string to store');
                CloseKey;
        end;
        Reg.Free;
end;

For example: This doesn't

{ In another unit, far far away... }
type
        TMyClass = class(TObject)
        private
                mstrSomething : string;
        public
                destructor Destroy; override;
end;

procedure TMyClass.Destroy;
var
        Reg : TRegistry;
begin
        inherited;
        Reg := TRegistry.Create;
        Reg.RootKey := HKEY_LOCAL_MACHINE;
        Access := KEY_ALL_ACCESS;
        if Reg.OpenKey('Some key structure', True) then begin
                WriteString('Some registry value', mstrSomething);
                CloseKey;
        end;
        Reg.Free;
end;

{ Back in the form unit on a button click or similar }
var
        objMine : TMyClass;
begin
        objMine := TMyClass.Create;
        // Assume code in here which assigns to member variables of TMyClass
        objMine.Free;
end;

Does the fact that the code to save is in the destructor cause life problems
for
the registry class?

Thoughts anyone?

Tony Sinclair
Holliday Group Limited
Christchurch
New Zealand

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of [EMAIL PROTECTED]
Sent: Friday, 14 July 2000 16:46
To: Multiple recipients of list delphi
Subject: Re:RE: [DUG]: TRegistry


Just a thought...
I have found the following with NT - a real pain...

Creating a Registry entry in NT with code - I wanted to use RegEdit but did
not
have access rights to do so - I created a small app that just created the
Registry entry and set the value - I was able to do this...
This worked - the gotcha - The entry was not available (might / might not
have
been created - can't remember) until after a reboot - re logging in might
also
work...

HTH

Regards
Paul

____________________Reply Separator____________________
Subject:  RE: [DUG]:  TRegistry
Author:   [EMAIL PROTECTED]
Date:          14/07/2000 16:45



     I was aware of the issues writing / read to / from the registry in a
dll,
     but this is from just a standard exe.  It will create keys alright if
they
     are not there but anything to do with values, just won't work.  Doesn't
     create them if they aren't there.  This is on both NT and 98, NT is
logged
     on as administrator.  Creating the value entries myself doesn't solve
the
     problem either.

     -----Original Message-----
     From: Myles Penlington [mailto:[EMAIL PROTECTED]]
     Sent: Friday, 14 July 2000 16:20
     To: Multiple recipients of list delphi
     Subject: RE: [DUG]: TRegistry


     What are you writing from?

     An application should be no problem.
     A DLL or Service application can cause problems. In some cases NT
security
     will just not let you write to the registry (Especially a DLL). You
should
     be able to read okay.

     Myles.




     > -----Original Message-----
     > From:   Tony Sinclair [SMTP:[EMAIL PROTECTED]]
     > Sent:   Friday, July 14, 2000 4:26 PM
     > To:     Multiple recipients of list delphi
     > Subject:     [DUG]:  TRegistry
     >
     > Hi all,
     >
     > I am trying to get the T(Damn)Registry to save some values into
     > HKEY_LOCAL_MACHINE and it just won't do it.  Is there anything I need
to
     > do
     > special apart from
     >
     > RootKey
     > Access
     > OpenKey
     > WriteString
     > CloseKey
     >
     > Thanks in advance
     >
     > Tony Sinclair
     > Holliday Group Limited
     > Christchurch
     > New Zealand
     >
     >
     -----------------------------------------------------------------------
---
     > -
     >     New Zealand Delphi Users group - Delphi List -
[EMAIL PROTECTED]
     >                   Website: http://www.delphi.org.nz
     -----------------------------------------------------------------------
----
         New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                       Website: http://www.delphi.org.nz
     -----------------------------------------------------------------------
----
         New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                       Website: http://www.delphi.org.nz


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to