procedure TForm1.CheckBox1Click(Sender: TObject);
var
  tmp:TComponent;
begin
  if Sender is TCheckBox then
  begin
   tmp:=FindComponent('Edit'+copy((Sender as TCheckBox).Name,9,10));
   if tmp is TEdit then
      (tmp as TEdit).Enabled:= (Sender as TCheckBox).Checked;
  end;
end;

解决方案 »

  1.   

    procedure TForm1.CheckBox1Click(Sender: TObject);
    var
      tmp:TComponent;
    begin
      if Sender is TCheckBox then
      begin
       tmp:=FindComponent('Edit'+copy((Sender as TCheckBox).Name,9,10));
       if tmp is TEdit then
          (tmp as TEdit).Enabled:= (Sender as TCheckBox).Checked;
      end;
    end;
      

  2.   

    设置每一个checkbox1.click 的事件if CheckBox1.Checked then
       Begin
           Edit1.Enabled:=True;
       End
    else
       Begin
          Edit1.Enabled:=False;
       End;
      

  3.   

    for i := 1 to 24 do begin
        with Tcheckbox(FindComponent(checkbox + IntToStr(i))) do
        begin
          tEedit(findcomponent(edit+inttostr(i))).enabled=checked;
        end;
      end;
      

  4.   

    var i,j;
    i:=0;
    j:=29;
    for i:=1 to 29 do
       Begin
            if CheckBox1.Checked then
       Begin
           Edit1.Enabled:=True;
       End
    else
       Begin
          Edit1.Enabled:=False;
       End;
    End;
    把数字转换为i 就可以了。
      

  5.   

    FindComponentrocedure  ...
    var
      E:TComponent;
    begin
      if Sender is TCheckBox then
      begin
       E:=FindComponent('Edit'+copy((Sender as TCheckBox).Name,9,10));
       if E is TEdit then
          (E as TEdit).Enabled:= (Sender as TCheckBox).Checked;
      end;
    end;
    看上简单,其实也不难
      

  6.   

    var
      E:array[1..24] of TEdit;分别设定CheckBox1..CheckBox24的Tag为1..24
    在FormCreate事件中
      E[1]:=Edit1;
      E[2]:=Edit2;
      ...
      E[24:=Edit24;在CheckBoxClick事件中(所有的CheckBoxX的OnClick事件都指向同一处代码):
      E[(Sender as TComboBox).Tag].Enabled:=(Sender as TComboBox).Checked;
      

  7.   

    mfc2001(拔剑茫然心四顾)的方法适合初始化,我的方法适合每个checkbox的OnClick事件
      

  8.   

    for i := 1 to 24 do begin
    Begin
      TEedit(findcomponent(edit+inttostr(i))).enabled=Tcheckbox(FindComponent(checkbox + IntToStr(i))).checked;
    end;
      

  9.   

    to ihihonline(小小->充电中……):
    我用copy 10你干嘛也用10,我决定用100,呵呵
      

  10.   

    最好在每个checkbox的OnClick里添加代码
    procedure TForm1.CheckBox1Click(Sender: TObject);
    begin
      if CheckBox1.Checked then 
        Edit1.Enabled := True
      else 
        Edit1.Enabled := False;
    end;
    或者写个过程
    procedure CheckEnabled;
    var
      i: Integer;
    begin
      for i := 1 to 24 do
      begin
        if Assigned(FindComponent('CheckBox'+IntToStr(i))) 
         and Assigned(FindComponent('Edit'+IntToStr(i))) then
        begin
          if TCheckBox(FindComponent('CheckBox'+IntToStr(i))).Checked then
             TEdit(FindComponent('Edit'+IntToStr(i))).Enabled := True
          else
             TEdit(FindComponent('Edit'+IntToStr(i))).Enabled := False; 
        end;
      end;
    end;
      

  11.   

    最好的方法如下:
    设置每个CheckBox的Tag属性为指向相应Edit的指针就可以了,不过要在程序中指定。其他的不用我说了吧?呵呵
      

  12.   

    算了,还是写出来:
    TEdit(Pointer((Sender as TCheckBox).tag)).Enabled := (Sender as TCheckBox).Checked;
      

  13.   

    CreateForm中写:
    CheckBox1.Tag := integer(Edit1);
    CheckBox2.Tag := integer(Edit2);
    ......
      

  14.   

    (同意ihihonline(小小->充电中……) 和 newwen(玩一会儿))就是240个也是一段代码搞定,具体如下:type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
          ……
        CheckBox1: TCheckBox;
        CheckBox2: TCheckBox;
        CheckBox3: TCheckBox;
          ……
        procedure CheckBoxclick(Sender: TObject);   //Method Added      ……
        
    procedure TForm1.CheckBoxClick(Sender: TObject);
    var
      t : TComponent;
    begin
      if Sender is TCheckBox then
      begin
       t:=FindComponent('Edit'+copy((Sender as TCheckBox).Name,9,1));
      if t is TEdit then
       (t as TEdit).Enabled:= (Sender as TCheckBox).Checked;
      end;
    end;  不过一定要记得在各个CheckBox的Click事件中选择定义的CheckBoxClick方法!
      

  15.   

    for i:=1 to 24 do  begin
      with TCheckbox(FindComponent(Checkbox+IntToStr(i))) do
      begin
        TEdit(findComponent(Edit+intToStr(i))).enabled:=checked;
      end;
    end;
    确实不错!
    TEdit(Pointer(Sender as TCheckbox).tag)).Enable:=(sender as TCheckBox).checked;
      

  16.   

    疑问:用Copy合适么?,如果是 checkbox12 不出错么?
      

  17.   

    多谢各位啦,各种方法我都试过了,感觉 MSHawk(憨憨) ,qybao(阿宝) shindynj(一路奔走) 的方法都不错啦,就不一一讲了。
    总结一下吧,大题有这么几种
    用循环 
      for  i:=1  to  24  do    begin  
       with  TCheckbox(FindComponent(‘Checkbox'+IntToStr(i)))  do  
       begin  
           TEdit(findComponent('Edit'+intToStr(i))).enabled:=checked;  
       end;  
    end;   
    或直接引用TEdit(Pointer(Sender  as  TCheckbox).tag)).Enable:=(sender  as  TCheckBox).checked; 
    留给后来人:)