kwang080897
asked on
Saving a TFont
How do i save a Tfont to a file and load it again
i'm trying with
Stream.Write(Font,Sizeof(f ont));
Why does Size return 4 ??? (Some kind of pointer ??)
i'm trying with
Stream.Write(Font,Sizeof(f
Why does Size return 4 ??? (Some kind of pointer ??)
ASKER
Adjusted points to 100
What exactly do you want to achieve, kwang?
Alex
Alex
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(FontDial og1.Font);
end;
procedure TForm1.Button2Click(Sender : TObject);
var
FS : TFileStream;
begin
if opendialog1.Execute then
begin
FS := TFilestream.Create(Opendia log1.Filen ame,fmOpen read);
try
TComponent(FontDialog1) := FS.ReadComponent(FontDialo g1);
Memo1.Font.Assign(FontDial og1.Font);
finally
FS.Free;
end;
end;
end;
procedure TForm1.Button3Click(Sender : TObject);
var
FS : TFileStream;
begin
if savedialog1.Execute then
begin
FS := TFilestream.Create(Savedia log1.Filen ame,fmCrea te);
try
FontDialog1.Font.Assign(Me mo1.Font);
FS.WriteComponent(FontDial og1);
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
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
begin
If FontDialog1.Execute then
Memo1.Font.Assign(FontDial
end;
procedure TForm1.Button2Click(Sender
var
FS : TFileStream;
begin
if opendialog1.Execute then
begin
FS := TFilestream.Create(Opendia
try
TComponent(FontDialog1) := FS.ReadComponent(FontDialo
Memo1.Font.Assign(FontDial
finally
FS.Free;
end;
end;
end;
procedure TForm1.Button3Click(Sender
var
FS : TFileStream;
begin
if savedialog1.Execute then
begin
FS := TFilestream.Create(Savedia
try
FontDialog1.Font.Assign(Me
FS.WriteComponent(FontDial
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
ASKER
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
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
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 ?
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 ?
ASKER
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
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
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 ;-)
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 ;-)
Yup, TFormStorage.
ASKER
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
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
ASKER
Well maybe it is ......
How do i add Stored Props at runtime ??
How do i add Stored Props at runtime ??
ASKER
Found out........
Think i can use it
Jeurk !!! - Thanks - please submit an answer
Think i can use it
Jeurk !!! - Thanks - please submit an answer
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.
Cheers, ptm.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER