比如说要动态的生成n个label,并且还要指定他们的位置,该怎么做???
另外,请问有没有见过类似windows我的电脑的那种显示方式(图标,列表)的控件

解决方案 »

  1.   

    在Form的OnCreate事件中写:var
      LB_1:TLabel;
    LB_1:=TLabel.Create(Self);
    LB_1.Parent:=Form1;
    LB_1.Left:=100;
    LB_1.Top:=100;
    LB_1.Caption:='测试';
      

  2.   

    应该注意的是:你动态创建的对象,也需要你手动释放资源。LB_1.Free;
      

  3.   

    with TLabel.Create(Self) do
    begin
     Parent := self;
     Top := 100;
     Left := 100;
     Caption := 'Test;
     Visible := true;
    end;
      

  4.   

    循环是可以的, 但在声明的时候 
    var
      LB_1:TLabel;  这里是不能循环的。。
      

  5.   

    label类型的动态数组,是怎么声明的??? 哪位大哥指点下
      

  6.   

    var
      LB : array[1..n] of TLabel;  for i:=1 to n do
    begin
     LB[i]:=TLabel.Create(Self);
     LB[i].Parent:=Form1;
     LB[i].Left:=100;
     LB[i].Top:=50+i*dy;
     LB[i].Caption:='label'+inttostr[i];
    end;
      

  7.   

    楼上,你的代码是错误的,必须声明的是动态树组
      A: array of Tlabel;
      

  8.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      A: array of Tlabel;
      i,j:integer;
    begin
      i:=strtoint(edit1.text);
      setlength(a,i);
        for j:=0 to i-1 do
        begin
         a[j]:=TLabel.Create(Self);
         a[j].Parent:=Form1;
         a[j].Left:=100;
         a[j].Top:=50+i*10;
         a[j].Caption:='label'+inttostr(j);
        end;
    end;
      

  9.   

    楼上,你的程序可以运行
    但,要生成10个动态的lebel即在edit1中输入10
    程序只生成了 label2 和 label9,请问这是怎么会事啊???????
      

  10.   

    写错了饿,不好意思
    楼上的程序,如果我要生成10个动态的lebel即在edit1中输入10
    程序只生成了 label9,也就是最后一项,请问这是怎么会事啊???????
      

  11.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      A: array of Tlabel;
      i,j:integer;
    begin
      i:=strtoint(edit1.text);
      setlength(a,i);
        for j:=0 to i-1 do
        begin
         a[j]:=TLabel.Create(Self);
         a[j].Parent:=Form1;
         a[j].Left:=100;
         a[j].Top:=50+j*20;
         a[j].Caption:='label'+inttostr(j);
        end;
    end;