Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Sonstiges (https://www.delphipraxis.net/45-library-sonstiges/)
-   -   Font Eigenschaften <-> Inifile oder Registry (https://www.delphipraxis.net/23657-font-eigenschaften-inifile-oder-registry.html)

shmia 7. Jun 2004 14:18


Font Eigenschaften <-> Inifile oder Registry
 
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] = '1' then
    Font.Style := Font.Style + [fsBold];
  if Str[2] = '1' then
      Font.Style := Font.Style + [fsItalic];
  if Str[3] = '1' then
    Font.Style := Font.Style + [fsUnderline];
  if Str[4] = '1' then
    Font.Style := Font.Style + [fsStrikeOut];

  Delete(Str, 1, 5);

  // colour
  Font.Color := StringToColor(Str);
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:58 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz