Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to save the font settings of a control to the registry Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Aug-02
Category
Graphic
Language
Delphi 2.x
Views
47
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How can I save the font settings of a control to registry? Saving name , size, etc. 
as string/int doesn't seem the best way ... (as far as I remember , I can't even 
save all font options this way)

Answer:

You can create a little component (needs not be installed on the palette) that 
allows you to stream a fonts properties to a stream. The stream contents could then 
be saved to a binary key in the registry.


1   { ... }
2   type
3     TFontWrapper = class(TComponent)
4     private
5       FFont: TFont;
6       constructor Create(aOwner: TComponent); override;
7       destructor Destroy; override;
8       procedure SetFont(value: TFont);
9     published
10      property Font: TFont read FFont write SetFont;
11    end;
12  
13    { TFontWrapper }
14  
15  constructor TFontWrapper.Create(aOwner: TComponent);
16  begin
17    inherited;
18    FFont := TFont.Create;
19  end;
20  
21  destructor TFontWrapper.Destroy;
22  begin
23    FFont.Free;
24    inherited;
25  end;
26  
27  procedure TFontWrapper.SetFont(value: TFont);
28  begin
29    FFont.Assign(value);
30  end;
31  
32  { ms is a field of the form }
33  
34  procedure TForm1.Button1Click(Sender: TObject);
35  var
36    helper: TFontWrapper;
37  begin
38    if not Assigned(ms) then
39      ms := TMemoryStream.Create
40    else
41      ms.Clear;
42    helper := TFontWrapper.Create(nil);
43    try
44      helper.font := label1.font;
45      ms.WriteComponent(helper);
46    finally
47      helper.free;
48    end;
49    label1.font.size := label1.font.size + 2;
50  end;
51  
52  procedure TForm1.Button2Click(Sender: TObject);
53  var
54    helper: TFontWrapper;
55  begin
56    if not Assigned(ms) then
57      Exit;
58    ms.Position := 0;
59    helper := TFontWrapper.Create(nil);
60    try
61      ms.ReadComponent(helper);
62      label1.font := helper.font;
63    finally
64      helper.free;
65    end;
66  end;
67  
68  
69  //If reg is a TRegistry instance already with key open a
70  
71  
72  reg.WriteBinaryData(valuename, ms.Memory^, ms.Size);
73  
74  
75  //would save the streamed data to the registry,
76  
77  
78  ms.size := reg.GetDatasize(valuename);
79  reg.ReadBinaryData(valuename, ms.Memory^, ms.Size);


would read it back. Mind the caret!

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC