Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Saving a TFont

Posted on 1999-07-27
14
Medium Priority
?
397 Views
Last Modified: 2013-12-03
How do i save a Tfont to a file and load it again

i'm trying with
  Stream.Write(Font,Sizeof(font));

Why does Size return 4 ??? (Some kind of pointer ??)


0
Comment
Question by:kwang080897
[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
  • 2
  • +2
14 Comments
 

Author Comment

by:kwang080897
ID: 1391370
I need to save and load a lot of different components - so if there is any easy way to do this I would like to know
0
 

Author Comment

by:kwang080897
ID: 1391371
Adjusted points to 100
0
 
LVL 15

Expert Comment

by:simonet
ID: 1391372
What exactly do you want to achieve, kwang?

Alex
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 1391373
hi kwang,

you can do it with the internal delphi streaming methods

a sample how to save and load a font

unit stream_font_u;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    FontDialog1: TFontDialog;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  If FontDialog1.Execute then
    Memo1.Font.Assign(FontDialog1.Font);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  FS : TFileStream;
begin
  if opendialog1.Execute then
  begin
    FS := TFilestream.Create(Opendialog1.Filename,fmOpenread);
    try
      TComponent(FontDialog1) := FS.ReadComponent(FontDialog1);
      Memo1.Font.Assign(FontDialog1.Font);
    finally
      FS.Free;
    end;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  FS : TFileStream;
begin
  if savedialog1.Execute then
  begin
    FS := TFilestream.Create(Savedialog1.Filename,fmCreate);
    try
      FontDialog1.Font.Assign(Memo1.Font);
      FS.WriteComponent(FontDialog1);
    finally
      FS.Free;
    end;
  end;
end;

end.


the streaming methods can only applied to Tcomponents. Tfont is no tcomponentclass, therefore i save and load here the component tfontdialog.

this streaming methods can applied to all components.

meikl
0
 

Author Comment

by:kwang080897
ID: 1391374
I'm doing a Print Project......

and i would like to save my objects whith all the properties included

For eks. I have a Property :

PrinterFont : Tfont

It seem's like i can save it ok - but i Get an error when i try to load it
(this case with SaveComponentRes and LoadComponent)

So what i'm really looking for is a Method to Enumerate all components in my TPrintDoc object and save them...... and be able to load them again




0
 
LVL 4

Expert Comment

by:jeurk
ID: 1391375
Hi,
I suggest you get the rxLib and use the formstorage placement
component. It will do all the work for you.
The only way I found to save the fonts state is to save everything in the
registry or elsewhere, but by hand. This means you have
to save every property one after another, the size, the color, the name, the style
and even the style is to handle by hand, bold, underlined, etc...
So use the rxlib. Anyway, with that component it's a matter of two clicks.
Get it here : http://rx.demo.ru/
if you have problems with the install let me know. If you prefer I send you
a code sample of how I store and restore my font propertys, let me know too.

Oh, Maybe I'm wrong and I did not understand your question, you want
to save the font in a file, or the font propertys ?
0
 

Author Comment

by:kwang080897
ID: 1391376
Hi  meikl !!

Thanks.......

I will keep this open, because i would like to take this question a little futher..

A will post a seperate question to you - hope it's ok (please look at my other comment)


Kim
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1391377
hi kim,

well its ok.

the rx-library, suggested by jeurk, has a Component (TPlacement i guess), with which you can store some propertys into a ini-file or in the registry.

you should take a look to this great library.

meikl ;-)
0
 
LVL 4

Expert Comment

by:jeurk
ID: 1391378
Yup, TFormStorage.
0
 

Author Comment

by:kwang080897
ID: 1391379
Not just what i'm looking for.

In the end i should have some kind of file format, so i wont have the data in the registry, and i dont care about the placement of the form

0
 

Author Comment

by:kwang080897
ID: 1391380
Well maybe it is ......

How do i add Stored Props at runtime ??
0
 

Author Comment

by:kwang080897
ID: 1391381
Found out........

Think i can use it

 Jeurk !!! - Thanks - please submit an answer

0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 1391382
There are many diffrent ways to save components, but you have always to save their properties and not the whole object instance. You can save it as stream, as text, as XML or how you want to. In the load procedure you have just to set the properties to the value they had before.

Cheers, ptm.
0
 
LVL 4

Accepted Solution

by:
jeurk earned 400 total points
ID: 1391383
Hi,
I'm glad it solves your problem.
If you want the props stored in a file you can ask FormStorage
to place things in a .ini
The name is not too well chosen. I think properties repository
would be more appropriate. I think it lask a fonctionnality
I'd like to have. That is to be able to chose to store my global
variables too. That would be great. I agree that you can add the at runtime,
but design time would be better.
Regards...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

670 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