有9个label和一个edit,我想用edit来控制label显示的个数,如edit.text为1时,label1.caption为某值,而label2.caption-label9.caption为空,edit.text为2时,label1.caption和label2.caption为某值,而label3.caption-label9.caption为空,请问如何实现

解决方案 »

  1.   

    var   s : array of label
      i: integer;
    begin
      setlength(s,strtoint(edit1.text));
      for i:= 0 to high(s) -1 do 
      beign
       s[i] := TLabel.create(self);
       s[i].caption = 'jhj';  end;
    end;
      

  2.   

    label中不能显示jhj,是不是数组定义有问题
      

  3.   

    数组应定义为s:array of Tlable;而且主程序里应加入s[i].parent:=Form1;s[i].show;的语句,具体如下:procedure TForm1.Button1Click(Sender: TObject);
    const atop=20;
    var
      s : array of Tlabel ;
      i: integer;
    begin
      setlength(s,strtoint(edit1.text));
      for i:= 0 to high(s) do
      begin
       s[i] := TLabel.create(self);
       s[i].caption := 'jhj';
       s[i].parent:=Form1;
       s[i].Top:=i*atop;
       s[i].Show;  end;
    end;