Board index » delphi » using the registry.

using the registry.

I have been trying to save color settings in the registry with limited
success.

When I change the color of the main form the relevant registry entry does
change, but I can't seem to read this setting successfully on restarting the
program, that is, the color reverts to the color set at design time.

My code to write to the registry  is:

         procedure TForm1.FormDestroy(Sender: TObject);
        var
        reg :tregistry;
        begin
             reg := tregistry.create;
             try
             reg.openkey('Software\PHCompany\Toyodict' , true);
             reg.writeinteger('color' , color);
             finally
             reg.free;
         end;
        end;

My code to read from the registry is:

            procedure TForm1.FormActivate(Sender: TObject);
             var
             reg :tregistry;
             keygood: boolean;
             begin
             reg :=tregistry.create;
             try
             keygood :=reg.openkey('Software\PHCompany\Toyodict', true);
             if not keygood then begin
            form1.color:=reg.readinteger('color');
            end;
            finally
            reg.free;
            end;

I have checked and the registry setting exists and does change when I change
the color of the form at runtime.
But when the program is closed and restarted the correct color is not
displayed, instead it is the color set at design time. So I guess the
registry is not being read or if it is it is being overridden by something
else?
Does the designtime setting affect things?

Where should I put the read and write reg code? Currently I have the read
code in the formactivate event and the write code in the formdestroy event.

I am using the colordialog component to choose the form's color at runtime.

Thanks for your help.

cya

p...@typhoon.co.jp

 

Re:using the registry.


On Tue, 2 Feb 1999 10:16:31 +1000, "Peter Hatigan"

Quote
<p...@typhoon.co.jp> wrote:

>I have been trying to save color settings in the registry with limited
>success.

>When I change the color of the main form the relevant registry entry does
>change, but I can't seem to read this setting successfully on restarting the
>program, that is, the color reverts to the color set at design time.

>My code to write to the registry  is:

>         procedure TForm1.FormDestroy(Sender: TObject);
>        var
>        reg :tregistry;
>        begin
>             reg := tregistry.create;
>             try
>             reg.openkey('Software\PHCompany\Toyodict' , true);
>             reg.writeinteger('color' , color);
>             finally
>             reg.free;
>         end;
>        end;

>My code to read from the registry is:

>            procedure TForm1.FormActivate(Sender: TObject);
>             var
>             reg :tregistry;
>             keygood: boolean;
>             begin
>             reg :=tregistry.create;
>             try
>             keygood :=reg.openkey('Software\PHCompany\Toyodict', true);

make this
             keygood :=reg.openkey('Software\PHCompany\Toyodict',
false);
(is 'more civilised')

Quote
>             if not keygood then begin

shouldnt this be
               if keygood then begin
?

Quote
>            form1.color:=reg.readinteger('color');

And make this
                        Color := reg.readinteger('color');
just in case there might be more TForm1 variables around

Quote
>            end;
>            finally
>            reg.free;
>            end;

>I have checked and the registry setting exists and does change when I change
>the color of the form at runtime.
>But when the program is closed and restarted the correct color is not
>displayed, instead it is the color set at design time. So I guess the
>registry is not being read or if it is it is being overridden by something
>else?
>Does the designtime setting affect things?

Code (if modified as above) seems ok

Quote

>Where should I put the read and write reg code? Currently I have the read
>code in the formactivate event and the write code in the formdestroy event.

I would put the read code in the formcreate event. Seems more logical.

Quote
>I am using the colordialog component to choose the form's color at runtime.

>Thanks for your help.

>cya

>p...@typhoon.co.jp

------------------
David A. Schweizer

iec ProGAMMA, The Netherlands
d.a.schweizer[OK, i don't want any more spam]gamma.rug.nl
guess where the '@' goes ?

Re:using the registry.


On Tue, 2 Feb 1999 10:16:31 +1000, "Peter Hatigan"

Quote
<p...@typhoon.co.jp> wrote:
>My code to read from the registry is:

>            procedure TForm1.FormActivate(Sender: TObject);
>             var
>             reg :tregistry;
>             keygood: boolean;
>             begin
>             reg :=tregistry.create;
>             try
>             keygood :=reg.openkey('Software\PHCompany\Toyodict', true);
>             if not keygood then begin

This must be:
 if  keygood then ....

- Ulli -

The Coder's Knowledge Base
http://www.netalive.org/ckb

Other Threads