Delphi也可以實現(xiàn)控件數(shù)組,用定義數(shù)組變量實現(xiàn)控件數(shù)組
小弟表達(dá)能力有限,此文章又是本人第一次發(fā)表文檔,所以不周到之處請各位仁兄多多包涵。
我們在使用Delphi時有時會發(fā)現(xiàn)一個問題,就是Delphi沒有像VB或者VF等軟件一樣可以很方便的定義控件數(shù)組。小弟在編寫一個多媒休演示光盤的時候因要用到很多Image控件,而且如果沒有用控件數(shù)組的話將使程序?qū)懫饋矸浅B闊┒覐?fù)雜化。所以想了很久,最終決定用定義數(shù)組變量的方式來實現(xiàn)控件數(shù)組。
下面是代碼:
PRocedure Tfrm_main.FormCreate(Sender: TObject);
var
image:array[1..12] of TImage; //用于存放12個image圖像框
label:array[1..12] of TLabel;//用于存放12個label標(biāo)簽
begin
//將image對象付給image數(shù)組
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數(shù)組
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;
新聞熱點
疑難解答
圖片精選