Einzelnen Beitrag anzeigen

v2afrank

Registriert seit: 9. Mai 2005
Ort: Bocholt
573 Beiträge
 
Delphi XE2 Professional
 
#3

Re: Font-Attribute in INI-Datei speichern

  Alt 18. Jul 2006, 07:10
Ich bin mir nicht mehr sicher wo ich die Routinen gefunden habe. Funktionieren aber
Delphi-Quellcode:
function FontToString(Font: TFont): String;
begin
  // 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 = ',';
  EXCEPT_MSG = 'Invalid string to font conversion';
var
  i: Integer;
begin
  {any exception/error we encounter will ultimately
  result in an EConvertError being raised}

  // name
  i := Pos(SEP, Str);
  if i = 0 then
    raise EConvertError.Create(EXCEPT_MSG);
  Font.Name := Copy(Str, 1, i - 1);
  Delete(Str, 1, i);

  // size
  i := Pos(SEP, Str);
  if i = 0 then
    raise EConvertError.Create(EXCEPT_MSG);
  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_MSG);
  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;
  Mit Zitat antworten Zitat