Solved

TFont to String/Other SAVABLE data.

Posted on 2000-05-01
11
366 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
  • 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

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!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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