procedure TForm1.BitBtn1Click(Sender: TObject);
var
i,d,j:integer;
editm:tedit;
begin
d:=0;
j:=strtoint(num.text);
for i:=1 to j do
begin
editm :=tedit.Create(self);
with editm do
begin
editm.Parent:=ScrollBox1;
editm.Width:=120;
editm.Height:=20;
editm.Left:=0;
editm.Top:=0+d;
editm.Name:='edit'+inttostr(i);
editm.Text:='edit'+inttostr(i);
editm.Visible:=true;
d:=d+20;
end;
end;
给动态创建的Edit控件动态添加OnChange事件:
procedure TForm1.EditChange(Sender: TObject);
begin
showmessage(Tedit(Sender).text);
end;
procedure TForm1.EditChange(Sender: TObject);
begin
showmessage(Tedit(Sender).text);
end;
procedure TForm1.Button1Click(Sender: TObject);
var NewEdit:Tedit;
begin
NewEdit:=Tedit.Create(nil);
NewEdit.Parent:=self;
NewEdit.SetBounds(10,20,50,21);
NewEdit.OnChange:=EditChange;
end;