procedure CreateButtons(); var btnList:array of TBitbtn; //动态数组用于存放所要生成的按钮 imgList:array of TBitMap; //动态数组用于存放按钮的图片 i,iCount:integer; begin iCount := strtoint(edit1.text);//从EDIT1取得要生成的个数 setlength(btnList,SizeOf(TBitBtn)*iCount);//初始化动态数组的长度 setlength(imgList,SizeOf(TBitMap)*iCount);//初始化动态数组的长度
for i:=1 to iCount do //动态生成图片变量,并装入图片(假设图片名:pic1. begin //bmp,pic2.bmp.....pic100.bmp) imgList[i] := TBitmap.Create; imgList[i].LoadFromFile('pic'+inttostr(i)+'.bmp'); end;
for i:=1 to iCount do //动态生成,并装入图片。 begin btnList[i] := TBitBtn.Create(self); btnList[i].Parent := self; btnList[i].Top := 100; btnList[i].Left := 100 * i; btnList[i].Width := 90; btnList[i].Height := 50; btnList[i].Caption := 'Button '+inttostr(i); btnList[i].Glyph := imgList[i]; end; end;