Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving font info to the registry 1

Status
Not open for further replies.

sggaunt

Programmer
Jul 4, 2001
8,620
GB
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!

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
 
Ok I wrote some functions to UnOrd the Font styles into bools, and wrote them and the name, size and colour values into the registry with reginifile.
Done! as Gordon Ramsay would say.



Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top