Mastodon
Programmierung

Write all Font-Styles to the registry

Q: How to write all Font-Styles to the registry?

A:
True, but why handle the set elements in the first place? The following
functions save/restore a font via a single registry key:

[code lang=”delphi”] FontRec = packed record
Color: TColor;
LogFont: TLogFont;
end;

procedure LoadFont(reg: TRegistry; const key,id: string; font: TFont);
var fRec: FontRec;
begin
if reg.OpenKey(key,False) then try
if reg.ReadBinaryData(id,frec,SizeOf(fRec)) = SizeOf(fRec) then
font.Handle := CreateFontIndirect(fRec.LogFont);
font.Color := fRec.Color;
finally
reg.CloseKey;
end;
end;

procedure SaveFont(reg: TRegistry; const key,id: string; font: TFont);
var fRec: FontRec;
begin
if Windows.GetObject(font.Handle,SizeOf(fRec.LogFont),@fRec.LogFont) > 0
then begin
if reg.OpenKey(key,True) then try
fRec.Color := font.Color;
reg.WriteBinaryData(id,fRec,SizeOf(fRec));
finally
reg.CloseKey;
end;
end;
end;
[/code]

Mike Orriss (TeamB & Developer Express)

[tags]Delphi, Misc, Fonts[/tags]

0 Kommentare zu “Write all Font-Styles to the registry

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.