我用一个函数来创建一些LABEL和IMAGE,为什么会出错,是不是我的语法有错,请各位帮忙看一下,谢了!
label1:=Tlabel.Create(Application);
label2:=Tlabel.Create(Application);
label3:=Tlabel.Create(Application);
label4:=Tlabel.Create(Application);
label5:=Tlabel.Create(Application);
label6:=Tlabel.Create(Application);
label7:=Tlabel.Create(Application);
label8:=Tlabel.Create(Application); for i:=1 to 8 do
begin
TLabel(FindComponent('label' + inttostr(i))).Visible:=true;//从这就开始出错了
TLabel(FindComponent('label' + inttostr(i))).Font.Color:=clRed;
TLabel(FindComponent('label' + inttostr(i))).Font.Style:=[fsBold];
TLabel(FindComponent('label' + inttostr(i))).Font.Name:='隶书';
TLabel(FindComponent('label' + inttostr(i))).Transparent:=true; end;
for i:=1 to 4 do
begin
TLabel(FindComponent('label' + inttostr(i))).Top:=5;
TLabel(FindComponent('label' + inttostr(i+4))).Top:=212;
end;
label1.Left:=13;
label2.Left:=171;
label3.Left:=329;
label4.Left:=489;
label5.Left:=13;
label6.Left:=171;
label7.Left:=329;
label8.Left:=489;
image2:=Timage.Create(Application);
image3:=Timage.Create(Application);
image4:=Timage.Create(Application);
image5:=Timage.Create(Application);
image6:=Timage.Create(Application);
image7:=Timage.Create(Application);
image8:=Timage.Create(Application);
image9:=Timage.Create(Application);
image10:=Timage.Create(Application);
image11:=Timage.Create(Application);
image12:=Timage.Create(Application);
image13:=Timage.Create(Application);
image14:=Timage.Create(Application);
image15:=Timage.Create(Application);
image16:=Timage.Create(Application);
image17:=Timage.Create(Application);
for i:=2 to 5 do
begin
TImage(FindComponent('image' + inttostr(i))).Visible:=true;
TImage(FindComponent('image' + inttostr(i+4))).Visible:=true;
TImage(FindComponent('image' + inttostr(i+8))).Visible:=true;
TImage(FindComponent('image' + inttostr(i+12))).Visible:=true;
TImage(FindComponent('image' + inttostr(i))).Top :=0;
TImage(FindComponent('image' + inttostr(i+8))).Top :=0;
TImage(FindComponent('image' + inttostr(i+4))).Top :=210;
TImage(FindComponent('image' + inttostr(i+12))).Top :=210;
TImage(FindComponent('image' + inttostr(i))).Height:=210;
TImage(FindComponent('image' + inttostr(i+4))).Height:=210;
TImage(FindComponent('image' + inttostr(i+8))).Height:=197;
TImage(FindComponent('image' + inttostr(i+12))).Height:=197;
TImage(FindComponent('image' + inttostr(i))).Width:=157;
TImage(FindComponent('image' + inttostr(i+8))).Width:=143;
TImage(FindComponent('image' + inttostr(i+4))).Width:=157;
TImage(FindComponent('image' + inttostr(i+12))).Width:=143;
end;
image2.Left:=2;
image3.Left:=160;
image4.Left:=329;
image5.Left:=479;
image6.Left:=2;
image7.Left:=160;
image8.Left:=329;
image9.Left:=479;
image10.Left:=9;
image11.Left:=167;
image12.Left:=325;
image13.Left:=485;
image14.Left:=9;
image15.Left:=167;
image16.Left:=325;
image17.Left:=485;
label1:=Tlabel.Create(Application);
label2:=Tlabel.Create(Application);
label3:=Tlabel.Create(Application);
label4:=Tlabel.Create(Application);
label5:=Tlabel.Create(Application);
label6:=Tlabel.Create(Application);
label7:=Tlabel.Create(Application);
label8:=Tlabel.Create(Application); for i:=1 to 8 do
begin
TLabel(FindComponent('label' + inttostr(i))).Visible:=true;//从这就开始出错了
TLabel(FindComponent('label' + inttostr(i))).Font.Color:=clRed;
TLabel(FindComponent('label' + inttostr(i))).Font.Style:=[fsBold];
TLabel(FindComponent('label' + inttostr(i))).Font.Name:='隶书';
TLabel(FindComponent('label' + inttostr(i))).Transparent:=true; end;
for i:=1 to 4 do
begin
TLabel(FindComponent('label' + inttostr(i))).Top:=5;
TLabel(FindComponent('label' + inttostr(i+4))).Top:=212;
end;
label1.Left:=13;
label2.Left:=171;
label3.Left:=329;
label4.Left:=489;
label5.Left:=13;
label6.Left:=171;
label7.Left:=329;
label8.Left:=489;
image2:=Timage.Create(Application);
image3:=Timage.Create(Application);
image4:=Timage.Create(Application);
image5:=Timage.Create(Application);
image6:=Timage.Create(Application);
image7:=Timage.Create(Application);
image8:=Timage.Create(Application);
image9:=Timage.Create(Application);
image10:=Timage.Create(Application);
image11:=Timage.Create(Application);
image12:=Timage.Create(Application);
image13:=Timage.Create(Application);
image14:=Timage.Create(Application);
image15:=Timage.Create(Application);
image16:=Timage.Create(Application);
image17:=Timage.Create(Application);
for i:=2 to 5 do
begin
TImage(FindComponent('image' + inttostr(i))).Visible:=true;
TImage(FindComponent('image' + inttostr(i+4))).Visible:=true;
TImage(FindComponent('image' + inttostr(i+8))).Visible:=true;
TImage(FindComponent('image' + inttostr(i+12))).Visible:=true;
TImage(FindComponent('image' + inttostr(i))).Top :=0;
TImage(FindComponent('image' + inttostr(i+8))).Top :=0;
TImage(FindComponent('image' + inttostr(i+4))).Top :=210;
TImage(FindComponent('image' + inttostr(i+12))).Top :=210;
TImage(FindComponent('image' + inttostr(i))).Height:=210;
TImage(FindComponent('image' + inttostr(i+4))).Height:=210;
TImage(FindComponent('image' + inttostr(i+8))).Height:=197;
TImage(FindComponent('image' + inttostr(i+12))).Height:=197;
TImage(FindComponent('image' + inttostr(i))).Width:=157;
TImage(FindComponent('image' + inttostr(i+8))).Width:=143;
TImage(FindComponent('image' + inttostr(i+4))).Width:=157;
TImage(FindComponent('image' + inttostr(i+12))).Width:=143;
end;
image2.Left:=2;
image3.Left:=160;
image4.Left:=329;
image5.Left:=479;
image6.Left:=2;
image7.Left:=160;
image8.Left:=329;
image9.Left:=479;
image10.Left:=9;
image11.Left:=167;
image12.Left:=325;
image13.Left:=485;
image14.Left:=9;
image15.Left:=167;
image16.Left:=325;
image17.Left:=485;
Project mybmp.exe raisedexception class EAccessViolation with message "Access Violation at address 00543205 in module "mybmp.exe". Read of address 00000068. Process stopped. Use setp or Run to continue.
按你说的做也不行,我在每一句LabelX:=TLabel.Create(Application)之后加上一句LabelX.Name:='LabelX',还是出同样的错误提示
->
label1:=Tlabel.Create(Self);
->
label1:=Tlabel.Create;
labelX:=Tlabel.Create(Self);
当然TImage也要做相应的改动。
dddd[i]........处理