请问:我想把一个页面所有TEdit控件内的内容全删了,怎样用最简洁的语句实现?
我这样写了:
   Procedure Tform1.clearEdit(sender:Tobject);
begin
  if (sender is TEdit) then
     (sender as Tedit).Text:='';
end;
  但是调用的时候怎么确定其参数呢?或者用其他的方式实现呢?
  不得其解,望高人指点

解决方案 »

  1.   

    var
      frmComponent:TComponent;
      i:Integer;
    begin
      for i:=0 to ComponentCount-1 do
      begin
          frmComponent:=Components[i];
          if frmComponent is TEdit then (frmComponent as TEdit).clear;
      end;
    end
      

  2.   

    const
      //the Parent need to deal
      ParentStr = 3;
      TParentNameStr:  array[0..ParentStr] of string = ('TForm','TPageControl','TTabSheet','TPanel');
    procedure PreviewControl(wc: TWinControl);
    var
      i: integer;
    begin
      for i := 0 to wc.ControlCount-1 do     //遍历其子控件
      begin
        if wc.Controls[i].ClassName = 'TEdit' then   //如果是需要操作的控件
          TEdit(wc.Controls[i]).Text := ''
        end else                            //如果是其他控件(包括容器控件/需要回掉、不需处理的控件)
        begin
          if IsNeedDealType(wc.Controls[i].ClassName) then   //如果是容器控件/需要回掉
            PreviewChildren(TWinControl(wc.Controls[i]));
        end;
      end;
    end;function IsNeedDealParent(ClassName: ShortString): boolean;
    var
      i: integer;
    begin
      Result := false;
      for i := 0 to ParentStr do
        if ClassName = TParentNameStr[i] then
        begin
          Result := true;
          break;
        end;
    end;