Solved

TFont to String/Other SAVABLE data.

Posted on 2000-05-01
11
367 Views
Last Modified: 2010-05-18
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
Comment
Question by:Psylord
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
11 Comments
 
LVL 1

Accepted Solution

by:
rowisoft earned 120 total points
ID: 2765363
Hy!

Do this:
String := TFont.Name;

that's a string!!


bye
Robert
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2765417
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
 

Author Comment

by:Psylord
ID: 2766937
rowisoft,
As I stated... I'm not after the font name alone. Re-read my question. :)
0
Technology Partners: 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!

 

Author Comment

by:Psylord
ID: 2766971
mullet_attack,
What uses clause is this missing?
0
 

Author Comment

by:Psylord
ID: 2766973
Nevermind... Overlooked somthing. :)
Checking the code. :)~
0
 

Author Comment

by:Psylord
ID: 2772414
Adjusted points from 50 to 120
0
 

Author Comment

by:Psylord
ID: 2772415
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
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2772596
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
 

Author Comment

by:Psylord
ID: 2772612
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
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2772799
why did you give the points to Rowisoft?
0
 

Author Comment

by:Psylord
ID: 2775037
ARGH!

That sucked. I'll pay yeh back.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question