如何用循环程序来多个控制控件的属性?(20分)

Z

zjtony1981

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手,我想有一个循环程序来控制5个image或label控件的属性,要使image1 image2 image3 image4 image5 的image后面的数字由循环来控制,这个要如何来实现?我试过下面的程序可是不行: for i=1 to 5do
begin
image.picture=image1.picture end
它报错好象是image没有定义什么的!
 
T

TYZhang

Unregistered / Unconfirmed
GUEST, unregistred user!
for i=1 to 5do
if Assigned(Self.FindComponent('image'+IntToStr(i))) then
TImage(Self.FindComponent('image'+IntToStr(i))).picture=image1.picture end
 
B

bamboowzm

Unregistered / Unconfirmed
GUEST, unregistred user!
利用其tag和其owners的Controls来实现;
具体做法是将5个image或label控件的tag设定为1~5,放在Panel中
for I:=0 to Panel1.ControlCount-1do
begin
if (Panel1.Controls is TImage) then
begin
(Panel1.Controls as TTmage).picture:=image1.picture;
//通过其tag的不同可以将其区分开,实现进一不的控制
end;
end;
 
K

kouchun

Unregistered / Unconfirmed
GUEST, unregistred user!
for I:=0 to form1.ComponentCount-1do
begin
if (form1.Components is TImage) then
begin
if (form1.Components as TTmage).name:='image1' then
XXX
if (form1.Components as TTmage).name:='image2' then
XXX
end;
end;
 
Top Bottom