DELPHI也可以实现控件数组,用定义数组变量实现控件数组

Delphi教程 2025-08-19

Delphi也可以实现控件数组,用定义数组变量实现控件数组

 小弟表达能力有限,此文章又是本人第一次发表文档,所以不周到之处请各位仁兄多多包涵。

 我们在使用Delphi时有时会发现一个问题,就是Delphi没有像VB或者VF等软件一样可以很方便的定义控件数组。小弟在编写一个多媒休演示光盘的时候因要用到很多Image控件,而且如果没有用控件数组的话将使程序写起来非常麻烦而且复杂化。所以想了很久,最终决定用定义数组变量的方式来实现控件数组。

 下面是代码:

PRocedure Tfrm_main.FormCreate(Sender: TObject);

var

image:array[1..12] of TImage; //用于存放12个image图像框

label:array[1..12] of TLabel;//用于存放12个label标签

begin

//将image对象付给image数组

image[1]:=image1;

image[2]:=image2;

image[3]:=image3;

image[4]:=image4;

image[5]:=image5;

image[6]:=image6;

image[7]:=image7;

image[8]:=image8;

image[9]:=image9;

image[10]:=image10;

image[11]:=image11;

image[12]:=image12;

//将label对象付给label数组

label[1]:=label1;

label[2]:=label2;

label[3]:=label3;

label[4]:=label4;

label[5]:=label5;

label[6]:=label6;

label[7]:=label7;

label[8]:=label8;

label[9]:=label9;

label[10]:=label10;

label[11]:=label11;

label[12]:=label12;

end;