我知道可以分开CLEAR的方法,想问有更快的方法没?
 for i := 0 to Self.ComponentCount - 1 do
  begin
    if Self.Components[i] is TEdit then
      TEdit(Self.Components[i]).Text := '';
    if Self.Components[i] is TComboBox then
      TComboBox(Self.Components[i]).Text := ''; 
  end;
想问有没有方法把很多不同的组件全部CLEAR?

解决方案 »

  1.   

    每个组件都有自己的Class,要想一次清空比较麻烦,不过你的代码可以简化一下:procedure TForm1.Button1Click(Sender:TObject);
    var
      i:integer;
    begin
      for i:=0 to ControlCount-1 do
        if (Controls[i]is TEdit)or(Controls[i]is TComboBox)or(Controls[i]is TMemo) then
        begin
          TEdit(Controls[i]).Text:='';
          TComboBox(Controls[i]).Text:='';
          TMemo(Controls[i]).Text:='';
        end;
    end;