代码如下:
procedure ClearEdit(Form: TForm);
var i: integer;
begin
  for i:=0 to form.ComponentCount-1 do
  begin
    if (form.Components[i] is Tedit) then
       (form.Components[i] as Tedit).Text:='';
    if (form.Components[i] is TDBedit) then
       (form.Components[i] as TDBEdit).Text:='';
  end;
end;执行过程发现无效果,请大家解答

解决方案 »

  1.   

    procedure ClearEdit(wc:TWinControl);
    var i: integer;
    begin
      for i:=0 to wc.ControlCount-1 do
      begin
        if (wc.Controls[i] is Tedit) then
           (wc.Controls[i] as Tedit).Text:=''
        else if (wc.Controls[i] is TDBedit) then
           (wc.Controls[i] as TDBEdit).Text:=''
        else if (wc.Controls[i] is TWinControl then
          ClearEdit(wc);
      end;
    end;
      

  2.   

    firstshine(黑里透红) : 你那样我怎么调用啊?
      

  3.   

    procedure ClearEdit(Form: TForm);
    var i: integer;
    begin
      for i:=0 to form.ComponentCount-1 do
      begin
        if (form.Components[i] is Tedit) then
           (form.Components[i] as Tedit).Text:='';
        if (form.Components[i] is TDBedit) then
           (form.Components[i] as TDBEdit).Text:='';
      end;
    end;找不出什么错误,不过TDBEdit可以删除掉内容吗。看看Form参数传入有没有问题。
      

  4.   

    procedure TForm1.btn1Click(Sender: TObject);
    var i: integer;
    begin
      for i:=0 to form1.ComponentCount-1 do
      begin
        if (form1.Components[i] is Tedit) then
           (form1.Components[i] as Tedit).Text:='';
        if (form1.Components[i] is TDBedit) then
           (form1.Components[i] as TDBEdit).Text:='';
      end;
    end;没问题啊!
      

  5.   

    没问题
    你调用了ClearEdit么
      

  6.   

    你form里的text是动态创建的吗?
    如果是动态创建的话,你就要看看owner是谁!
      

  7.   

    你调用了ClearEdit么要么直接用edit1.clear这个笨方法
      

  8.   

    我试了一下  Edit类型的数据可以用你的方法清空
    DBedit的数据可以用(form1.Components[i] as TDBEdit).EditText:='';来清空
      

  9.   

    TDBEdit(form.Components[i]).Text:='';和你的一样,不过可以试一下,呵呵
      

  10.   

    我是想调用ClearEditI()来清空指定FORM上的输入框,但是测试发现两种输入框都无法清空
      

  11.   

    TDBEdit  清空后,如果不提交,也没用吧
      

  12.   

    经过测试,发现把ClearEdit放到公共模块中然后在form1中点按钮调用ClearEdit(form1)时无效,不解!!
      

  13.   

    form改成self
    ------------------
    测试通过!多谢,可是谁能告诉我为什么必须是self呢?准备揭贴
      

  14.   

    //  100 全 给我吧,递归清除
    procedure TFormCYBase.ClearText(AControl:TWinControl);
    var
      I: Integer;
    begin
      for I := 0 to AControl.ControlCount - 1 do    // Iterate
      begin
        //需清空处理控件
        if AControl.Controls[i] is TCustomEdit then
        begin
          (AControl.Controls[i] as TCustomEdit).Text:='';
        end;
        if AControl.Controls[i] is TCustomComboBox then
        begin
          (AControl.Controls[i] as TCustomComboBox).ClearSelection;
        end;
        //可以 作为 父亲的控件处理事件。
        if AControl.Controls[i] is TCustomControl  then
        begin
          ClearText(AControl.Controls[i] as TCustomControl);
        end;
      end;
    end;procedure TFormCYBase.BitBtn1Click(Sender: TObject);
    begin
      ClearText(self);
    end;
      

  15.   

    要找容器对象,而不仅是 Form ,
    Panel,GroupBox 都有可能
      

  16.   

    参数
    self相当于引用
    form1相当于传值当然只有引用才起效果。
      

  17.   

    你根本没理清情况。如果换中情况。
    在form1中要清空form2中的内容怎么办,那么self就救不了你了!
      

  18.   

    对class参数,没有引用和传值的区别,都是引用,实际就是个指针。应该不是self的问题,找找其他原因。你的函数不属于某个类的,调用self根本就会出错。
    procedure ClearEdit(Form: TForm);试一下刷新,或跟踪一下是否你要清空的edit执行了你清空的代码。
      

  19.   

    procedure TForm1.Button1Click(Sender: TObject);
    var i: integer;
    begin
      for i:=0 to form1.ComponentCount-1 do
      begin
        if (form1.Components[i] is Tedit) then
           (form1.Components[i] as Tedit).Text:='';
        if (form1.Components[i] is TDBedit) then
           (form1.Components[i] as TDBEdit).Text:='';
      end;
    end;
    代码没问题,看看是不是别的地方的错误。
      

  20.   

    应该用递归, form.components 并不包括 form 上的所有控件, 比如放在 panel 或 pageControl 上的控件就不包括在内
    所以必须有个递归来循环设置 form 上的所有容器控件内的 edit 才有效
      

  21.   

    没看出问题,不过应该看一下form属于谁
      

  22.   

    BabyGoblin(一笑冰寒): 你错了,form.controls才是你说的那种情况,我试过的
    ok,揭贴