[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

TFont to String/Other SAVABLE data.

In my application, I wish to allow the user to pick different font settings for things, and I want to save them in an ini file. The problem is, I have no idea how do get a TFont into a string. I'm not looking for just the font name, I want the style, name and size altogether. THis needs to be put in a string for saving/loading, so I can apply it to components and such.

Regards,
Psylord
0
Psylord
Asked:
Psylord
  • 7
  • 3
1 Solution
 
rowisoftCommented:
Hy!

Do this:
String := TFont.Name;

that's a string!!


bye
Robert
0
 
mullet_attackCommented:
Try this

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TMyFontData = packed record
  Name : string[50];
  Size : integer;
  Style : TFontStyles;
end;

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
MyFontData, MoreFontData : TMyFontData;
s : string;
begin
  with MyFontData Do
    begin
      Name := 'Some Font';
      Size := 8;
      Style := [fsBold];
    end;
  SetLength(s, Sizeof(TMyFontData));
  // put the data in a string
  CopyMemory(PChar(s),@MyFontData,Sizeof(TMyFontData));

  // read the string back into a record
  CopyMemory(@MoreFontData,PChar(s),Sizeof(TMyFontData));

end;

end.
0
 
PsylordAuthor Commented:
rowisoft,
As I stated... I'm not after the font name alone. Re-read my question. :)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
PsylordAuthor Commented:
mullet_attack,
What uses clause is this missing?
0
 
PsylordAuthor Commented:
Nevermind... Overlooked somthing. :)
Checking the code. :)~
0
 
PsylordAuthor Commented:
Adjusted points from 50 to 120
0
 
PsylordAuthor Commented:
mullet,

Can you do me one more thing on this?

Convert this so it writes/reads the info from an ini file and then applies it to a component...


THen the points are yours.
0
 
mullet_attackCommented:
In the true spirit of re-usable code, I hate writing stuff that others have already written (I am lazy...)

have a look at this :
http://www.delphizine.com/features/1997/10/di199710rv_f/di199710rv_f.asp

it's a component that you can select properties from your objects on your form and save the values to the registry.

That brings me to another question. Why are you using ini files? For 95/98/NT development, it's usual to store stuff in the registry. I personally don't _like_ to do this, but I do 'cos everyones else does, and people expect to be able to find stuff in the registry. If you haven't used the registry before, it's almost exactly the same as using ini files. Delphi makes it _real_ easy.

If you must use ini files, then the component in the article mentioned above could easily be modified to write to a file instead of the registry.
0
 
PsylordAuthor Commented:
Not what I was looking for really but I can make it work.

Thanks for the effort though. I have more important questions to worry about though. ;)
0
 
mullet_attackCommented:
why did you give the points to Rowisoft?
0
 
PsylordAuthor Commented:
ARGH!

That sucked. I'll pay yeh back.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now