__________________________________________路有尽,道无涯__________________________________________

【Profound__爱生活__诗意地栖息】

C/C++ || Python || Linux || 单片机 || 嵌入式 || 机器视觉

  博客园  :: 首页  :: 新随笔  ::  :: 订阅 订阅  :: 管理
The following example creates 20 edit boxes, using FindComponent with the edit box name to access each newly created edit box
procedure TForm1.Button1Click(Sender: TObject);
 1 var
 2   i: Integer;
 3 const
 4   NamePrefix = 'MyEdit';
 5 begin
 6   for i := 1 to 20 do begin
 7     TEdit.Create(Self).Name := NamePrefix + IntToStr(i);
 8     with TEdit(FindComponent(NamePrefix + IntToStr(i))) do
 9     begin
10       Left := 10;
11       Top := i * 20;
12       Parent := self;
13     end;
14   end;
15 end;

 



**********************************************************************

动态创建控件(属性和Tag)并绑定事件test

 1 procedure TForm1.test(Sender: TObject);  
 2 var  
 3    l_busin_flag:Integer;  
 4 begin  
 5    l_busin_flag:=(Sender as TButton).Tag;  
 6    ShowMessage(IntToStr(l_busin_flag)+'Hello');  
 7 end;  
 8   
 9 procedure TForm1.FormCreate(Sender: TObject);  
10 var  
11   btns: TButton;  
12   i:Integer;  
13 begin  
14   for i:=0  to  5 do  
15   begin  
16       btns:=TButton.Create(Self);  
17       btns.Width:=100;  
18       btns.Height:=20;  
19       btns.Caption:=IntToStr(i)+'动态按钮';  
20       btns.OnClick:=test;  
21       btns.Left:=i*100;  
22       btns.Tag:=i;  
23       btns.Parent:=Self;  
24   end;  
25 end;  

 

posted on 2016-07-14 16:11  HiRong  阅读(245)  评论(0)    收藏  举报
__________________________________________路有尽,道无涯__________________________________________