Announcement

Collapse
No announcement yet.

String in Font umwandeln?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • String in Font umwandeln?

    Hallo, Delphianer.
    Wisst ihr, wie man einen String in einen Font umwandeln kann?
    DAnke schon mal imvoraus, CH. Weber
    If it's there and you can see it – it's REAL
    If it's there and you can't see it – it's TRANSPARENT
    If it's not there and you can see it – it's VIRTUAL
    If it's not there and you can't see it – it's GONE!

  • #2
    Einen String kann ich mit einem Font sicher irgendwo darstellen, aber umwandeln kann ich da nix. Ich gehe aber mal davon aus, dass die Frage nur etwas ungelücklich gestellt wurde?<p>
    Mari
    Schöne Grüße, Mario

    Comment


    • #3
      Ich weiss zwar nicht mehr genau wo ich es her habe. Es funktioniert aber

      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] = '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;

      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

      Comment

      Working...
      X