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;
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步