for i:= 0 to  Form1.ControlCount - 1  do
   if(Form1.Controls[i].ClassName = 'TButton') then
    (Form1.Controls[i] as TButton).Enabled:=false;好像if哪里一直得不到真.我form上有button阿

解决方案 »

  1.   

    你的Button是不是放在Panel上面了?
      

  2.   

    楼上正解直接用 Form1 ,不是好习惯 ,用 self.//函数单元。
    procedure TESCDispose.ClearText(AControl:TWinControl);
    var
      I: Integer;
    begin
      for I := 0 to AControl.ControlCount - 1 do    // Iterate
      begin
        //需清空处理控件
        if AControl.Controls[i] is TEdit then
        begin
          (AControl.Controls[i] as TEdit).Text:='';
        end;
      end;
    end;//函数调用
    procedure TESCDispose.MyKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      // ESC 键处理事件。
      if (Key = VK_ESCAPE)  then
      begin
        ClearText(self);
      end;
    end;
      

  3.   

    当你的Button的parent不是Form时,用Form1.Control是不会找到该Button的你的代码可以改成
    for i:= 0 to  Self.ComponentCount - 1  do
       if(Self.Components[i].ClassName = 'TButton') then
        (Self.Components[i] as TButton).Enabled:=false;这样就可以遍历窗体上所有Button了
      

  4.   

    我觉得吧,其实form1,self都不要写、
    就象vc那样。