问题是这个样子的:我需要有不确定数目的CheckBox需要显示,具体的个数要根据程序前面用户的填写内容而变的。那么,请问我如何才能够根据用户填写的数目来在某一个地方显示相同的某一个控件(比如CheckBox)。问题是,建立好了以后,还要能够在下一步进行继续操作。比如,用户需要10个CheckBox,在显示出10个CheckBox以后,用户会作出选择。程序将根据用户的选择进行下一步的处理。

解决方案 »

  1.   

    procedure myProc(sender: tobject);
    begin
    if sender is tbutton then
      ShowMessage(inttostr((sender as tbutton).tag)));
    end;
    可以这样
    with btn[1] do
    begin
    Tag:=1;
    OnClick:=MyProc;
    end;....
      

  2.   

    var
      Form1: TForm1;
      btn:array[0..9] of TButton;var
      i:Integer;begin
      for i := 0 to 9 do
      begin
        btn[i]:=TButton.Create(Self);
        with btn[i] do
        begin
          Top:=30*i;
          Left:=0;
          Show;
          OnClick:=ButtonClick;
        end;
      end;
    end;procedure TForm.ButtonClick(Sender:TObject)
    begin
      if (Sender as TButton)=btn[0] then
        ...
      else (Sender as TButton)=btn[1] then
        ...
      ...
    end;
      

  3.   

    我做考试系统时做过,思路可以是这样:
    for ( 从i:=0开始到用户填的数)
    begin
    new 生成checkbox 每个的区别就是随i变化如名为:check i 
    end
    上面是生成。下面是读:
    for ( 从i:=0开始到用户填的数)
    begin
        if check i .checked then
        处理end
      

  4.   

    type
      TForm1 = class(TForm)
        Button1: TButton;   //这个按钮是我放在窗体上的按钮,通过单击此按钮动态生成一个新的按钮
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        procedure buttonClickEvent(sender:TObject);  //手动添加
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.buttonClickEvent(sender:TObject);    //手动添加函数的实现
    begin
      showMessage('asdlfj;lasdkfj;asdlfjasl');
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      button:TButton;  //这里动态生成一个按钮
    begin
      button:=TButton.Create(form1);
      button.Caption:='http://www.goomoo.net';
      button.Left:=20;
      button.Width:=300;
      button.Top:=20;
      button.OnClick:=buttonClickEvent;
      button.Parent:=form1;
    end;
      

  5.   

    xianxiliu(林桤) :
    我以前看到好象就是你说的这种,可是,能否麻烦您一下给一个比较具体的例子呢?
    比如,你说的New是怎么个用法呢?
      

  6.   

    var
      n :Integer;
      aa: TButton;
    begin
      for n := 1 to 10 do
      begin
        aa := TButton.Create(Self);
        aa.Parent := Form1;
        aa.Name := 'Test' + IntToStr(n);
        aa.Top := n * 10;
        aa.Left := n * 20;
      end;
    end;如果是checkbox或radio改一下就可以了
      

  7.   

    可到我网站看看www.52007.8u8.com
      

  8.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
     tt:array of tlabel;
     i:integer;
    begin
      for i:=1 to 10 do //可以动态生成不定的对象1 to 20 就是20个
       begin
        setlength(tt,i);
        tt[i-1]:=tlabel.create(form1);
        tt[i-1].parent:=form1;
        tt[i-1].left:=10+i*20;
        tt[i-1].Top :=1;
        tt[i-1].width:=10;
        tt[i-1].caption:=inttostr(i);
        edit4.Text:=tt[5].Caption;    //在这里出错了!
        end;
    end;
    上面的代码为什么错误了呢?
      

  9.   

    xianxiliu(林桤) :
    你的网站,我去了也。整个网叶都是你自己做的么?连同那个07的软件?你太牛了!另外,我照您的提示做了,如下:
    var
      n :Integer;
      aa: TCheckBox;
    begin
      for n := 1 to 10 do
      begin
        aa := TCheckBox.Create(Self);
        aa.Parent := Form1;
        aa.Name := 'Test' + IntToStr(n);
        aa.Top := n * 30;
        aa.Left :=  40;
      end;
    end;
    问题是,我怎么才能够知道某个CheckBox被选中了呢?
      

  10.   

    我有edit4的。拖放在界面上的。
      

  11.   

    xianxiliu(林桤) :
    对不起我在上面的代码中犯了一个极其愚蠢的错误了。我应该把Edit4.text:=aa[5].caption放在循环的外面的。问题总算是有了眉目了。谢谢楼上的二位了。加分揭贴了!