Wenn dies Ihr erster Besuch hier ist,
lesen Sie bitte zuerst die Hilfe - Häufig gestellte Fragen
durch. Sie müssen sich vermutlich registrieren,
bevor Sie Beiträge verfassen können. Klicken Sie oben auf 'Registrieren', um den Registrierungsprozess zu
starten. Sie können auch jetzt schon Beiträge lesen. Suchen Sie sich einfach das Forum aus, das Sie am meisten
interessiert.
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!
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
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