Re: Tfont



On Fri, 26 Aug 2005 11:01:44 +1200, anthony wrote:

> is it possible to turn a tFont into a string so I can save what the font of
> a certain component is
>
> I am want to store the fonts and background colors, so that when the
> appication restarts it will load the attributes for me.
>
> Anthony

Here's a couple of solutions that I grabbed from an unknown Delphi page a
long time ago:

1. very easy but not result isn't compact and effective (by data storage)


procedure SaveFont(FStream: TIniFile; Section: string; smFont: TFont);
begin
FStream.WriteString(Section, Ident + 'Name', smFont.Name);
FStream.WriteInteger(Section, Ident + 'CharSet', smFont.CharSet);
FStream.WriteInteger(Section, Ident + 'Color', smFont.Color);
FStream.WriteInteger(Section, Ident + 'Size', smFont.Size);
FStream.WriteInteger(Section, Ident + 'Style', Byte(smFont.Style));
end;

procedure LoadFont(FStream: TIniFile; Section: string; smFont: TFont);
begin
smFont.Name := FStream.ReadString(Section, Ident + 'Name', smFont.Name);
smFont.CharSet := TFontCharSet(FStream.ReadInteger(Section, Ident +
'CharSet', smFont.CharSet));
smFont.Color := TColor(FStream.ReadInteger(Section, Ident + 'Color',
smFont.Color));
smFont.Size := FStream.ReadInteger(Section, Ident + 'Size', smFont.Size);
smFont.Style := TFontStyles(Byte(FStream.ReadInteger(Section, Ident +
'Style', Byte(smFont.Style))));
end;

2. more hardly than first method, but result is compact. I use this method
in all own apps.


procedure SaveFont(FStream: TIniFile; Section: string; smFont: TFont);
begin
FStream.WriteString(Section, 'Font', smFont.Name + ',' +
IntToStr(smFont.CharSet) + ',' +
IntToStr(smFont.Color) + ',' +
IntToStr(smFont.Size) + ',' +
IntToStr(Byte(smFont.Style)));
end;

procedure LoadFont(FStream: TIniFile; Section: string; smFont: TFont);
var s, Data: string;
i: Integer;
begin
s := FStream.ReadString(Section, 'Font', ',,,,');
try
i := Pos(',', s);
if i > 0 then
begin
{Name}
Data := Trim(Copy(s, 1, i-1));
if Data <> '' then
smFont.Name := Data;
Delete(s, 1, i);
i := Pos(',', s);
if i > 0 then
begin
{CharSet}
Data := Trim(Copy(s, 1, i-1));
if Data <> '' then
smFont.Charset := TFontCharSet(StrToIntDef(Data,
smFont.Charset));
Delete(s, 1, i);
i := Pos(',', s);
if i > 0 then
begin
{Color}
Data := Trim(Copy(s, 1, i-1));
if Data <> '' then
smFont.Color := TColor(StrToIntDef(Data, smFont.Color));
Delete(s, 1, i);
i := Pos(',', s);
if i > 0 then
begin
{Size}
Data := Trim(Copy(s, 1, i-1));
if Data <> '' then
smFont.Size := StrToIntDef(Data, smFont.Size);
Delete(s, 1, i);
{Style}
Data := Trim(s);
if Data <> '' then
smFont.Style := TFontStyles(Byte(StrToIntDef(Data,
Byte(smFont.Style))));
end
end
end
end;
except
end;
end;
.



Relevant Pages

  • Re: Regex help needed
    ... > Paul McGuire wrote: ... > Now I want the ident to pull out 'fprintf(outFile ... Is there supposed to be a real line break in the string ... input string, and matches expressions until it finds a mismatch, or runs out ...
    (comp.lang.python)
  • Re: Patching Ident field of an Image
    ... Anders.Wallin@om.com (Anders Wallin) writes: ... Maybe you can just use the editor... ... The ident is a counted ascii string with the count beginning at %xF0 ... assign some value to the ident field during your build to make it ...
    (comp.os.vms)
  • Re: [PATCH] DMI: allow omitting ident strings in DMI tables
    ... Let's consider entries with empty ident but initialized ... first match slot as a valid entry and not as end-of-table marker. ... You are free to use an empty string as the ident. ...
    (Linux-Kernel)
  • Re: Passing a string as reference from a VB 3.0 application to a VC++ 3.0 DLL
    ... Well, the problem was in the declare function in the VB code, the String ... ident As String, ByRef size As Long) As Integer ... > I'm trying to make a DLL that contains a procedure that receives a string ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Tfont
    ... the font and colors of a Tlistbox I am wanting to save. ... > FStream.WriteInteger(Section, Ident + 'CharSet', smFont.CharSet); ... but result is compact. ...
    (alt.comp.lang.borland-delphi)