Solved

TFont to String/Other SAVABLE data.

Posted on 2000-05-01
11
363 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
Comment Utility
Hy!

Do this:
String := TFont.Name;

that's a string!!


bye
Robert
0
 
LVL 2

Expert Comment

by:mullet_attack
Comment Utility
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
Comment Utility
rowisoft,
As I stated... I'm not after the font name alone. Re-read my question. :)
0
 

Author Comment

by:Psylord
Comment Utility
mullet_attack,
What uses clause is this missing?
0
 

Author Comment

by:Psylord
Comment Utility
Nevermind... Overlooked somthing. :)
Checking the code. :)~
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Psylord
Comment Utility
Adjusted points from 50 to 120
0
 

Author Comment

by:Psylord
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
why did you give the points to Rowisoft?
0
 

Author Comment

by:Psylord
Comment Utility
ARGH!

That sucked. I'll pay yeh back.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now