home *** CD-ROM | disk | FTP | other *** search
- unit sf2beta;
-
- { This tries to load an entire form all in one go. It seems to work fine.
- It loads the form and all its components. However, there is a hidden
- problem. Try saving the form. Then, using the Delphi form designer, move
- one of the buttons. Recompile and load your saved form.
- Oops!
- }
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Button2: TButton;
- Edit1: TEdit;
- Button3: TButton;
- Label1: TLabel;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
-
- private
- { Private declarations }
- public
- { Public declarations }
- procedure ZapComponents;
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
-
-
- {$R *.DFM}
-
-
- procedure TForm1.ZapComponents;
- var
- i : integer;
- begin
- for i := 0 to (ComponentCount - 1) do
- Form1.RemoveComponent(Components[0]);
- end;
-
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- fs : TFileStream;
- begin
- fs := TFileStream.Create( 'xxx.txt', fmCreate );
- try
- fs.WriteComponent(Form1);
- label1.Caption := 'Saved';
- finally
- fs.Free;
- end;
- end;
-
-
- procedure TForm1.Button2Click(Sender: TObject);
- var
- fs : TFileStream;
- begin
- fs := TFileStream.Create( 'xxx.txt', fmOpenRead );
- ZapComponents;
- try
- fs.ReadComponent(Form1);
- label1.Caption := 'Loaded';
- finally
- fs.Free;
- end;
- end;
-
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- Caption := Edit1.Text;
- end;
-
- initialization
-
- end.
-