我用一个函数来创建一些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;

解决方案 »

  1.   

    提示的错误信息:
    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.
      

  2.   

    FindComponent('label' + inttostr(i))的返回值是nil,因为你用label1:=Tlabel.Create(Application)创建出来的label1的名字(即label1.Name)为空,而不是label1,所以你后面所有引用FindComponent('label' + inttostr(i))的语句都会导致读取内存错误。正确的做法是在你每一句LabelX:=TLabel.Create(Application)之后加上一句LabelX.Name:='LabelX'(这里的X=1,2,3...7,8),后面的TImage也要做同样的处理。
      

  3.   

    to  CareYouOnly(只在乎你) 
    按你说的做也不行,我在每一句LabelX:=TLabel.Create(Application)之后加上一句LabelX.Name:='LabelX',还是出同样的错误提示
      

  4.   

    label1:=Tlabel.Create(Application);
    ->
    label1:=Tlabel.Create(Self);
      

  5.   

    label1:=Tlabel.Create(Application);
    ->
    label1:=Tlabel.Create;
      

  6.   

    To kjbdyw (小文) 除了上面的改动外(看我上面的代码),还要将labelX:=Tlabel.Create(Application);改为
    labelX:=Tlabel.Create(Self);
    当然TImage也要做相应的改动。
      

  7.   

    创建控件不出错了,但是在窗口上却不能显示出来控件,这是为什么?我把它们的Visible属性设置为true并LoadFromFile了图片都不能显示。
      

  8.   

    用控件数组 array  dddd[22]   tedit  
    dddd[i]........处理 
      

  9.   

    label1:=Tlabel.Create(你需要显示的的窗体)