Autor Beitrag
Rool
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 211



BeitragVerfasst: Sa 26.07.03 12:49 
wie speichere ich am besten eine TFont-Instanz in der registry (also, dass color, schriftart, größe usw. gespeichert bleiben...)

_________________
MFG Rool
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Sa 26.07.03 13:04 
Hallo!

Ich hab hier mal zwei Funktionen um alle Eigenschaften einer TFont in einem String umzuwandeln und wieder zurück. Dadurch hast du die Möglichkeit z. B. einen einzelnen String (der alle Eigenschaften enthält) in die Registry zu speichern. Die Quelle ist mir leider nicht mehr bekannt.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
Uses
  SysUtils

const
  csfsBold      = '|Bold';
  csfsItalic    = '|Italic';
  csfsUnderline = '|Underline';
  csfsStrikeout = '|Strikeout';

// Konvertiert einen Font in einen darstellbaren String
// Output format: "April", 9, [Bold|Italic], [clAqua]
function FontToString(Font : TFont) : string;
var
  sStyle : string;
begin
  with Font do
  begin
    // convert font style to string
    sStyle := '';

    if( fsBold in Style )then
      sStyle := sStyle + csfsBold;

    if( fsItalic in Style )then
      sStyle := sStyle + csfsItalic;

    if( fsUnderline in Style )then
      sStyle := sStyle + csfsUnderline;

    if( fsStrikeout in Style )then
      sStyle := sStyle + csfsStrikeout;

    if( ( Length( sStyle ) > 0 ) and
        ( '|' = sStyle[ 1 ] ) )then
    begin
      sStyle :=
        Copy( sStyle, 2,
          Length( sStyle ) - 1 );
    end;

    Result := Format(
      '"%s", %d, [%s], [%s]',
      [ Name,
        Size,
        sStyle,
        ColorToString( Color ) ] );
  end;
end;

// Konvertiert einen darstellbaren String in einen Font
// Expected format:
//   "Arial", 9, [Bold], [clRed]
procedure StringToFont(  sFont : stringvar Font : TFont );
var
  p      : integer;
  sStyle : string;
begin
  // -------------------------------------
  if Length(sFont)=0 then begin
    sFont := '"Arial", 10, [], [clWindowText]';
  end;
  // -------------------------------------
  with Font do begin
    // get font name
    p    := Pos( ',', sFont );
    if p>0 then begin
      Name := Copy( sFont, 2, p-3 );
      Delete( sFont, 1, p );
    end;
    // -----------------------------------
    // get font size
    p    := Pos( ',', sFont );
    if p>0 then begin
      Size := StrToInt( Copy( sFont, 2, p-2 ) );
      Delete( sFont, 1, p );
    end;
    // -----------------------------------
    // get font style
    p      := Pos( ',', sFont );
    if p>0 then begin
      sStyle := '|' + Copy( sFont, 3, p-4 );
      Delete( sFont, 1, p );
    end;
    // -----------------------------------
    // get font color
    try
    Color :=
      StringToColor(
        Copy( sFont, 3,
          Length( sFont ) - 3 ) );
    except;
    end;
    // -----------------------------------
    // convert str font style to font style
    Style := [];
    if( Pos( csfsBold, sStyle ) > 0 )then
      Style := Style + [ fsBold ];

    if( Pos( csfsItalic, sStyle ) > 0 )then
      Style := Style + [ fsItalic ];

    if( Pos( csfsUnderline, sStyle ) > 0 )then
      Style := Style + [ fsUnderline ];

    if( Pos( csfsStrikeout, sStyle ) > 0 )then
      Style := Style + [ fsStrikeout ];
  end;
  // -------------------------------------
end;


Nicht schön aber es sollte funktionieren.

Gruß
Tino
Rool Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 211



BeitragVerfasst: Sa 26.07.03 13:09 
Titel: ..
jo geht doch klar! danke!

_________________
MFG Rool