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 components to a file or stream (2) 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
20-Oct-02
Category
Files Operation
Language
Delphi 2.x
Views
75
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I would like to stream selected components (say a panel with some other components 
on it) to a DFM like (text preferred over binary) file and be able to load it and 
restore them programatically.

Answer:

You need to save this component with root (where its handlers are declared), f.e., 
with TFormX:

1   { ... }
2   type
3     TForm1 = class(TForm)
4       MyComponent: TMyComponent;
5       procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
6     private
7       { Private declarations }
8     public
9       constructor Create(AOwner: TComponent); override;
10      function FormFileName: string;
11      { Public declarations }
12    end;
13  
14  var
15    Form1: TForm1;
16  
17  implementation
18  
19  {$R *.DFM}
20  
21  function TForm1.FormFilename: string;
22  begin
23    Result := ExtractFilePath(ParamStr(0)) + Classname + '.DAT';
24  end;
25  
26  constructor TForm1.Create(AOwner: TComponent);
27  var
28    fname: string;
29  begin
30    RegisterClass(TMyComponent); {And anything else that is required }
31    fname := FormFilename;
32    if FileExists(fname) then
33    begin
34      CreateNew(AOwner);
35      ReadComponentResFile(fname, Self);
36    end
37    else
38      inherited Create(AOwner);
39  end;
40  
41  procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
42  begin
43    WriteComponentResFile(FormFileName, Self);
44    UnregisterClass(TMyComponent);
45  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