Board index » delphi » Loading Font Name from file

Loading Font Name from file

I need to save the data in my application, and load it again in the
next session. To do this I write an ascii file to disk. One of the
parameters that I need to save is the Font (more specifically only the
Font name) of text that I draw on a canvas.

I can write the Font name to file OK, and can read this back as a
string, but cannot read it back into a TFont. How do I go about
assigning a string to MyFont.name ?

Any help appreciated
Liesl

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 

Re:Loading Font Name from file


Hi !

You could set the property TFont.Name from your loaded string value.

--

Bjoerge

<<
mercur...@hotbot.com skrev i meldingen <7ntade$6a...@nnrp1.deja.com>...
I need to save the data in my application, and load it again in the
next session. To do this I write an ascii file to disk. One of the
parameters that I need to save is the Font (more specifically only the
Font name) of text that I draw on a canvas.

I can write the Font name to file OK, and can read this back as a
string, but cannot read it back into a TFont. How do I go about
assigning a string to MyFont.name ?

Any help appreciated
Liesl

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Quote

Re:Loading Font Name from file


Just a simple assignment:

Font.Name := String;

If you are not going to store it in a binary way, and want to save the
characteristics of a font then all you should need is the font name,
style, size and color.

The Name, Sizea and style can be written as a string, and the eastest
way to write the color is using the RGB values or storing it as an
integer.  If you want to do the latter, here is some code that gets and
sets using an INI file..

{------------------------------------------------------------------------------}
function TConfig.Load_Settings : Boolean;
var
 TmpClrValue : Integer;
begin
 Result := True;
 {..}
  try
   try
   {..}
    TmpClrValue := FCCL_INI.ReadInteger('Color, Fonts', 'KeywordsBkClr',
DefaultWhite);
    FKW_BK_Color := IntToColor(TmpClrValue);
    FKW_Font.Name :=  Trim(FCCL_INI.ReadString('Color,
Fonts','KeywordsFont','Arial'));
    FKW_Font.Size :=  FCCL_INI.ReadInteger('Color, Fonts',
'KeywordsFontSize',8);
    TmpClrValue  :=  FCCL_INI.ReadInteger('Color, Fonts',
'FilenamesBkClr', DefaultWhite);
    FCF_BK_Color := IntToColor(TmpClrValue);
    FCF_Font.Name :=  Trim(FCCL_INI.ReadString('Color, Fonts',
'FilenamesFont','Arial'));
    FCF_Font.Size :=  FCCL_INI.ReadInteger('Color, Fonts',
'FilenamesFontSize',8);

   except
    Result := False;
    ErrorState := ecOpenFile;
   end;
  finally

   if Assigned(FCCL_INI) then
    begin
     FCCL_INI.Free;
     FCCL_INI := nil;
    end;
  end;
end;

Then I used a couple of functions to do the conversions ...

{-------------------------------------------------}
function TConfig.ColorToInt(Clr: TColor): Integer;
var
 RGBClr : Integer;
begin
 Result := -1;
 try
  RGBClr :=  Integer(Clr);
  Result := RGBClr;
 except

 end;

end;

{------------------------------------------------------------------------------}
function TConfig.IntToColor(Int: Integer): TColor;
var
  RGBClr : Integer;
begin
 Result := clNone;
 try
  RGBClr := Int;
  Result :=  TColor(RGBClr);
 except

 end; {try except}
end;

HTH

Rkr

Quote
mercur...@hotbot.com wrote:

> I need to save the data in my application, and load it again in the
> next session. To do this I write an ascii file to disk. One of the
> parameters that I need to save is the Font (more specifically only the
> Font name) of text that I draw on a canvas.

> I can write the Font name to file OK, and can read this back as a
> string, but cannot read it back into a TFont. How do I go about
> assigning a string to MyFont.name ?

> Any help appreciated
> Liesl

> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

Other Threads