我一直认为你要写控件的属性!
如果只是记录数据在外部文件里,下面有的例子!只用Tstream就可以!
如果要达到你的要求还要修改!我只记录TEdit类!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
List:Tlist;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterClasses([TEdit]);
List:=Tlist.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if Assigned(List) then List.Free;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var T:TControl;
begin
T:=TEdit.Create(Self);
with (T as TEdit) do
begin
Parent:=self;
Left:=x;
Top:=y;
Visible:=True;
end;
List.Add(T);
end;
procedure TForm1.Button1Click(Sender: TObject);
var S:TFileStream;
i:integer;
begin
try
s:=TFileStream.Create('save',fmopenwrite or fmcreate);
for i :=0 to list.Count-1 do
begin
s.WriteComponent(TControl(list));
end;
finally
s.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var S:TFileStream;
var T:TComponent;
begin
try
s:=TFileStream.Create('save',fmopenRead);
while s.Position<s.Size do
begin
T:=s.ReadComponent(Nil);
InsertControl(T as TControl);
end;
finally
s.Free;
end;
end;
end.