I needed a quick answer to this and found this code, seems to save into the registry OK, and the 'Loader' version seems to work fine.
But if I call this at shutdown, the application does not shut down cleanly.
I get a 'external application error' in the debug session,
and Delphi cannot successfully close the app at all.
I have to close it with Task Manger. and windows struggles to do that.
Running outside of the debugger things are even worse.
Multiple access violation errors that cannot be closed!
calling code, F is global TFont
Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
But if I call this at shutdown, the application does not shut down cleanly.
I get a 'external application error' in the debug session,
and Delphi cannot successfully close the app at all.
I have to close it with Task Manger. and windows struggles to do that.
Running outside of the debugger things are even worse.
Multiple access violation errors that cannot be closed!
Code:
procedure TForm1.SaveFont(aFont: TFont);
var
iSiz: Integer;
FontDesc: TFontDescription;
Reg: TRegistry;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
iSiz := SizeOf(FontDesc.LogFont);
if GetObject(aFont.Handle, iSiz, @FontDesc.LogFont) > 0 then
begin
if Reg.OpenKey('Software\'+ SECTION, True) then
try
FontDesc.Color := aFont.Color;
Reg.WriteBinaryData('Font', FontDesc, SizeOf(FontDesc));
finally
Reg.CloseKey;
end;
end;
// free the registry object
Reg.Free;
end;
calling code, F is global TFont
Code:
procedure TForm1.FormClick(Sender: TObject);
begin
WriteRegistry;
SetRegistryValue(RunAtStart.Checked);
//F := Togo.Font;
//SaveFont(F); // comment out all is OK
freeandnil(F);
close;
end;
Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain