In a similar vein, perhaps you should move the "inherited;" line in Destroy
after the rest of your code. An ancestor class may be invalidating your
variable in the inherited call.
Cheers,
Carl
-----Original Message-----
From: Bevan Edwards [mailto:[EMAIL PROTECTED]]
Sent: Friday, 14 July 2000 8:07 PM
To: Multiple recipients of list delphi
Subject: Re: [DUG]: TRegistry
Hi Tony,
Have you tried writing a specific string to the Registry instead of a
member variable - perhaps the variable has already been destroyed?
Regards,
Bevan
Tony Sinclair wrote:
>
> 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
<snip>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz