Author: William Gerbert
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:
1 function SaveFont(F_Font: TFont): boolean;
2 var3 FLog: TLogFont;
4 Reggy: TRegistry;
5 begin6 GetObject(F_Font.Handle, SizeOf(FLog), @FLog);
7 Reggy := TRegistry.Create;
8 try9 Reggy.OpenKey({'\REGKEYNAME'}, true);
10 Reggy.WriteBinaryData({'VALUENAME'}, FLog, SizeOf(FLog));
11 result := true;
12 finally13 Reggy.Free;
14 end;
15 end;
16 17 18 //Get a font:19 20 21 function SetFont(F_Font: TFont): boolean;
22 var23 FLog: TLogFont;
24 Reggy: TRegistry;
25 NewFHnd: longint;
26 begin27 result := false;
28 Reggy := TRegistry.Create;
29 try30 if Reggy.OpenKey({'\REGKEYNAME'}, false) and31 Reggy.ValueExists({'VALUENAME'}) then32 begin33 Reggy.ReadBinaryData({'VALUENAME'}, FLog, SizeOf(FLog));
34 {set Font to the retrieved font}35 NewFHnd := CreateFontIndirect(FLog);
36 result := (NewFHnd <> 0);
37 if result then38 F_Font.Handle := NewFHnd;
39 end;
40 finally41 Reggy.Free;
42 end;
43 end;