home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / handson / archive / Issue151 / delphi / SaveForm2 / sf2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-01-18  |  1.4 KB  |  83 lines

  1. unit sf2;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Button2: TButton;
  13.     Edit1: TEdit;
  14.     Button3: TButton;
  15.     Label1: TLabel;
  16.     procedure Button1Click(Sender: TObject);
  17.     procedure Button2Click(Sender: TObject);
  18.     procedure Button3Click(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.     procedure ZapComponents;
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31.  
  32.  
  33. {$R *.DFM}
  34.  
  35.  
  36. procedure TForm1.ZapComponents;
  37. var
  38.    i : integer;
  39. begin
  40.    for i := 0 to ComponentCount - 1 do
  41.    begin
  42.       TControl(Components[0]).Parent := nil;
  43.       Form1.RemoveComponent(Components[0]);
  44.    end;
  45. end;
  46.  
  47. procedure TForm1.Button1Click(Sender: TObject);
  48. var
  49.   fs : TFileStream;
  50. begin
  51.   fs := TFileStream.Create( 'xxx.txt', fmCreate );
  52.   try
  53.     fs.WriteComponent(Form1);
  54.     label1.Caption := 'Saved';
  55.   finally
  56.     fs.Free;
  57.   end;
  58. end;
  59.  
  60.  
  61. procedure TForm1.Button2Click(Sender: TObject);
  62. var
  63.   fs : TFileStream;
  64. begin
  65.   fs := TFileStream.Create( 'xxx.txt', fmOpenRead );
  66.   ZapComponents;
  67.   try
  68.      fs.ReadComponent(Form1);
  69.      label1.Caption := 'Loaded';
  70.   finally
  71.     fs.Free;
  72.   end;
  73. end;
  74.  
  75. procedure TForm1.Button3Click(Sender: TObject);
  76. begin
  77.   Caption := Edit1.Text;
  78. end;
  79.  
  80. initialization
  81.  
  82. end.
  83.