是不是只能挨个的把text属性置为空啊? 有没有别的方法,比如关闭窗口再重新打开的方法?

解决方案 »

  1.   

    清空Form上所有TEdit.Textvar
      I: Integer;
    begin
      for I := 0 to ComponentCount - 1 do
        if Components[I] is TEdit then
          TEdit(COmponents[I]).Text := '';
    end;
      

  2.   

    uses TypInfo;
    var
      int1:Integer;
      PropInfo:PPropInfo;
    begin
      for int1:=0 to ComponentCount-1 do
      begin
        PropInfo:= GetPropInfo( Components[int1], 'text' );
        if PropInfo <> nil then
          SetObjectProp( Components[ int1 ], PropInfo, nil );
      end;
      

  3.   

    楼上的方法有点缺陷!如果出现panel,edit在panel上,上述方法无法清除
    建议做个递归procedure TForm1.Button1Click(Sender: TObject);
    var
      I:integer;
    begin
        For I:=0 to self.ComponentCount-1 do
        begin
           if Components[I] is TEdit then
           TEdit(Components[I]).Text := '';
           if  Components[I] is TPanel then  //或者类似于panel的组件容器
           ClearText(Components[I]);
        end;
    end;procedure TForm1.ClearText(Cons:TComponent);
    var
      I:integer;
    begin
        For I:=0 to Cons.ComponentCount-1 do      //
        begin
           if Components[I] is TEdit then
            TEdit(Components[I]).Text := '';
           if  Components[I] is TPanel then  //或者类似于panel的组件容器
           ClearText(Components[I]);
        end;
    end;
      

  4.   

    不好意思,可以直接使用ClearText递归函数 这样调用
    clearText(Form)!
      

  5.   

    ComponentCount 方法是正解.如果有些要清空,有些不用,则设置EDIT 的TAG属性.要删除的时候判断一下。
      

  6.   

    在Form上使用Components不存在递归的问题,因为所有Component的Owner都是Form,使用Controls时才存在递归
      

  7.   

    maozefa(阿发伯) 说得是 大意了  ,component类是control的父类,原来我做这个的时候用的是controls  因为edit是它的子类,用component遍历太浪费,就楼主的问题改装没改好,向阿发伯学习!
      

  8.   

    to winxkm(蹩脚的程序员)
    回答问题时考虑不周或者出错是正常的,我就经常这样,回复一发出再看,啊,错了,哈哈,有时可补充说明挽救,有时没得救,只好认错,我认为这不丢人,而是美德。向我学习,哈哈,我脸都红了,幸亏你看不见。^_^
      

  9.   

    不是只有TEdit 有text属性,容器也不只TPanel 一个
      

  10.   

    清除Form上的所有控件的Text可以这样:
    type
      TMyControl = class(TControl)
      public
        property Text;
      end;procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to ComponentCount - 1 do
        if Components[I] is TControl then
          TMyControl(Components[I]).Text := '';
    end;