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 create a form that saves its component state automatically 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
28-Oct-02
Category
VCL-Forms
Language
Delphi 2.x
Views
84
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I would like to know how to save a forms appearance once it has been changed by a 
user.

Answer:

1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
7   StdCtrls,
8       ExtCtrls;
9   
10  type
11    TForm1 = class(TForm)
12      Edit1: TEdit;
13      Edit2: TEdit;
14      Edit3: TEdit;
15      Memo1: TMemo;
16      CheckBox1: TCheckBox;
17      CheckBox2: TCheckBox;
18      CheckBox3: TCheckBox;
19      RadioGroup1: TRadioGroup;
20      Button1: TButton;
21      procedure Button1Click(Sender: TObject);
22      procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
23    private
24      function FormFilename: string;
25    public
26      constructor Create(aOwner: TComponent); override;
27    end;
28  
29  var
30    Form1: TForm1;
31  
32  implementation
33  
34  {$R *.DFM}
35  
36  procedure TForm1.Button1Click(Sender: TObject);
37  begin
38    close
39  end;
40  
41  procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
42  var
43    fs: TFilestream;
44  begin
45    fs := TFilestream.Create(FormFilename, fmCreate);
46    try
47      fs.WriteComponent(self);
48    finally
49      fs.free;
50    end;
51  end;
52  
53  function TForm1.FormFilename: string;
54  begin
55    Result := ExtractFilePath(ParamStr(0)) + Classname + '.DAT';
56  end;
57  
58  constructor TForm1.Create(aOwner: TComponent);
59  var
60    fs: TFileStream;
61    fname: string;
62  begin
63    fname := FormFilename;
64    if FileExists(fname) then
65    begin
66      CreateNew(aOwner);
67      fs := TFileStream.Create(fname, fmOpenread or fmShareDenyWrite);
68      try
69        fs.ReadComponent(self);
70      finally
71        fs.free;
72      end;
73    end
74    else
75      inherited Create(aOwner);
76  end;
77  
78  end.


			
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