How to save and restore font properties in the registry (3) (Views: 27)
Problem/Question/Abstract: What is the best way to store the font for a TDBGrid. I can change it fine with a Font Dialog but how can i store those settings so they take effect the next time the user fires up the program ? Answer: Save a font: function SaveFont(F_Font: TFont): boolean; var FLog: TLogFont; Reggy: TRegistry; begin GetObject(F_Font.Handle, SizeOf(FLog), @FLog); Reggy := TRegistry.Create; try Reggy.OpenKey({'\REGKEYNAME'}, true); Reggy.WriteBinaryData({'VALUENAME'}, FLog, SizeOf(FLog)); result := true; finally Reggy.Free; end; end; Get a font: function SetFont(F_Font: TFont): boolean; var FLog: TLogFont; Reggy: TRegistry; NewFHnd: longint; begin result := false; Reggy := TRegistry.Create; try if Reggy.OpenKey({'\REGKEYNAME'}, false) and Reggy.ValueExists({'VALUENAME'}) then begin Reggy.ReadBinaryData({'VALUENAME'}, FLog, SizeOf(FLog)); {set Font to the retrieved font} NewFHnd := CreateFontIndirect(FLog); result := (NewFHnd <> 0); if result then F_Font.Handle := NewFHnd; end; finally Reggy.Free; end; end; |