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