例如:
  我想在edit控件得到焦點時改變顏色,在失去焦點時改回來,當edit很多時,我能不能用一行代碼完成呢?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      iLoop:Integer;
    begin
      for iLoop :=0 to Self.ComponentCount-1 do
      begin
        if (Self.Components[iLoop] is TEdit) then
        begin
          TEdit(Self.Components[iLoop]).Color := clGreen;
        end;
      end;
    end;
      

  2.   

    楼上的正确,如果只判断Edit的话,可以将ComponentCount换成ControlCount,会增加一点点效率,将相应的Components换成Controls