L
liceblone
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, DBCtrls;
type
TForm1 = class(TForm)
createcontrol: TButton;
savecontrol: TButton;
loadcomponent: TButton;
procedure createcontrolClick(Sender: TObject);
procedure savecontrolClick(Sender: TObject);
procedure loadcomponentClick(Sender: TObject);
procedure changecolor(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const filename:string='c:/a.txt';
implementation
{$R *.dfm}
procedure TForm1.createcontrolClick(Sender: TObject);
var dbedit:Tdbedit;
i:integer;
begin
for i:=0 to 5 do
begin
dbedit:=Tdbedit.Create (self);
dbedit.Parent:=self;
dbedit.Top :=i*20;
dbedit.Onclick :=changecolor;
end;
end;
procedure TForm1.savecontrolClick(Sender: TObject);
var ms:Tmemorystream;
i:integer;
begin
ms:=Tmemorystream.Create ;
for i:=0 to self.ComponentCount -1 do
begin
if self.Components is tdbedit then
ms.WriteComponent((self.Componentsas tdbedit ));
end;
ms.SaveToFile(filename );
ms.Free ;
end;
procedure TForm1.loadcomponentClick(Sender: TObject);
var i:integer;
var ms:Tmemorystream;
var ldbedit:tdbedit;
begin
try
classes.FindClass('Tdbedit');
except
on exception do
classes.RegisterClass(Tdbedit);
end;
if fileexists(filename) then
begin
ms:=tmemorystream.Create ;
ms.LoadFromFile(filename);
for i:= 0 to 5 do
begin
ldbedit:=Tdbedit(ms.ReadComponent(nil) );
ldbedit.Parent :=self; //在load之后为什么onclick属性会丢掉??????
end;
end;
end;
procedure TForm1.changecolor(Sender: TObject);
begin
if sender is tdbedit then
begin
(sender as tdbedit).Color :=10;
end;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, DBCtrls;
type
TForm1 = class(TForm)
createcontrol: TButton;
savecontrol: TButton;
loadcomponent: TButton;
procedure createcontrolClick(Sender: TObject);
procedure savecontrolClick(Sender: TObject);
procedure loadcomponentClick(Sender: TObject);
procedure changecolor(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const filename:string='c:/a.txt';
implementation
{$R *.dfm}
procedure TForm1.createcontrolClick(Sender: TObject);
var dbedit:Tdbedit;
i:integer;
begin
for i:=0 to 5 do
begin
dbedit:=Tdbedit.Create (self);
dbedit.Parent:=self;
dbedit.Top :=i*20;
dbedit.Onclick :=changecolor;
end;
end;
procedure TForm1.savecontrolClick(Sender: TObject);
var ms:Tmemorystream;
i:integer;
begin
ms:=Tmemorystream.Create ;
for i:=0 to self.ComponentCount -1 do
begin
if self.Components is tdbedit then
ms.WriteComponent((self.Componentsas tdbedit ));
end;
ms.SaveToFile(filename );
ms.Free ;
end;
procedure TForm1.loadcomponentClick(Sender: TObject);
var i:integer;
var ms:Tmemorystream;
var ldbedit:tdbedit;
begin
try
classes.FindClass('Tdbedit');
except
on exception do
classes.RegisterClass(Tdbedit);
end;
if fileexists(filename) then
begin
ms:=tmemorystream.Create ;
ms.LoadFromFile(filename);
for i:= 0 to 5 do
begin
ldbedit:=Tdbedit(ms.ReadComponent(nil) );
ldbedit.Parent :=self; //在load之后为什么onclick属性会丢掉??????
end;
end;
end;
procedure TForm1.changecolor(Sender: TObject);
begin
if sender is tdbedit then
begin
(sender as tdbedit).Color :=10;
end;
end;
end.