Einzelnen Beitrag anzeigen

shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 

Font Eigenschaften <-> Inifile oder Registry

  Alt 7. Jun 2004, 14:18
Mit den folgenden Funktionen kann man die Eigenschaften eines TFont-Objektes in eine Inidatei oder die Registry speichern und laden.
Dazu werden die Font-Eigenschaften in einen String konvertiert bzw. die Font-Eigenschaften aus einem String extrahiert:
Delphi-Quellcode:
Uses ...,Graphics;
resourcestring
  EXCEPT_MSG1 = 'Invalid string to font conversion';

function FontToString(Font: TFont) : String;
begin
  Assert(Assigned(Font));
  // name, size, bold, italic, underline, strikethrough, colour
  Result := Format('%s,%d,%d%d%d%d,%s', [Font.Name, Font.Size,
    Integer(fsBold in Font.Style), Integer(fsItalic in Font.Style),
    Integer(fsUnderline in Font.Style), Integer(fsStrikeOut in Font.Style),
    ColorToString(Font.Color)]);
end;

procedure StringToFont(Str: String; Font: TFont);
const
  SEP = ',';
var
  i: Integer;
begin
  Assert(Assigned(Font));
  // name
  i := Pos(SEP, Str);
  if i = 0 then raise EConvertError.Create(EXCEPT_MSG1);
  Font.Name := Copy(Str, 1, i-1);
  Delete(Str, 1, i);

  // size
  i := Pos(SEP, Str);
  if i = 0 then raise EConvertError.Create(EXCEPT_MSG1);
  Font.Size := StrToInt(Copy(Str, 1, i-1));
  Delete(Str, 1, i);

  // bold, italic, underline, strikethrough
  if Pos(SEP, Str) <> 5 then raise EConvertError.Create(EXCEPT_MSG1);
  Font.Style := [];
  if Str[1] = '1then
    Font.Style := Font.Style + [fsBold];
  if Str[2] = '1then
      Font.Style := Font.Style + [fsItalic];
  if Str[3] = '1then
    Font.Style := Font.Style + [fsUnderline];
  if Str[4] = '1then
    Font.Style := Font.Style + [fsStrikeOut];

  Delete(Str, 1, 5);

  // colour
  Font.Color := StringToColor(Str);
end;
Andreas
  Mit Zitat antworten Zitat