var
    i:  integer;
begin
for I := 1 to query1.recordcount do
 TCheckbox(FindComponent('Checkbox'+IntToStr(I))).Caption:=IntToStr(I);
end;

解决方案 »

  1.   

    如果你的checkbox是按数据库顺序建的,就按楼上说的做就可以了
      

  2.   

    呵呵,直接用楼上的方法是比较危险的, 很容易出异常.
    1. FindComponent要通过CheckBox的Owner来调用
       如: CheckBox的Owner为Form, 则Form.FindComponent() 若为Pannel,则用Pannel.FindComponent()2.不要直接写
    TCheckbox(FindComponent('Checkbox'+IntToStr(I))).Caption:=IntToStr(I);  因为FindComponent()有返回值可能是Nil, 那时,这要写就肯定会出异常了! 可改为;
      aCheckBox := TCheckbox(FindComponent('Checkbox'+IntToStr(I)));
      if aCheckBox <> nil then aCheckBox.Caption := '你要写的值'注意这两点,应该就没什么问题了!
      

  3.   

    不能编译过 ,TCheckBox :Undeclared Identified ,如何办 ?大哥
      

  4.   

    名字设为 “Checkbox”+IntToStr(i) 不好。名字还是设为你想要的名字。
    建议使用 MyCheckbox.Tag 将他们分别设为 ID,
    for i<ComponentCount
    begin
    aCheckBox = aCheckBox := TCheckbox(Components[i]);
    if aCheckBox <> nil then begin
    if aCheckBox.tag=ID then aCheckBox.Caption="...";
    end
    end
      

  5.   

    var
        i:  integer;
        a:  tcomponent; 
    begin
    for I := 1 to query1.recordcount do
     a:=FindComponent('Checkbox'+IntToStr(I))
     a.Caption:=IntToStr(I);
    end;
      

  6.   

    var
        i:  integer;
        a:  tcomponent; 
    begin
    for I := 1 to query1.recordcount do
      begin
       a:=FindComponent('Checkbox'+IntToStr(I))
       a.Caption:=IntToStr(I);
      end;
    end;
      

  7.   

    呵呵,你要uses StdCtrls; 这个单元才行呀!
      

  8.   

    不能编译过 ,TCheckBox :Undeclared Identified ,如何办 ?大哥
    经典!