edit 的小问题:
   一个窗体里有15个edit和一个button,怎么在点button时判断15个edit中有空的edit,就是不允许edit中的内容为空。
  千万不要用15个if 语句;
  好象有句代码  (sender as TEdit).tag 可以,只有一句代码,是怎么写的

解决方案 »

  1.   

    Var
      I : Integer;
    begin
      for I ;= Form.Componentcount - 1 do 
        if Form.Components[I] is TEdit then
           if TEdit(Form.Components[I]).text = '' then;//就这样;
              begin
              end
    end;
      

  2.   

    var
      i : integer;
    begin
      for i:= 0 to componentcount - 1 do 
        if components[i] is TEdit then
           if TEdit(Components[i]).text = '' then
       {}
    end;
      

  3.   

    var
      i:integer;
    begin
    for i:=0 to Form1.ControlCount-1 do
      if Form1.Controls[i] is TEdit then
        if (Form1.Controls[i] as TEdit).Text='' then
          ShowMessage((Form1.Controls[i] as TEdit).Name+'为空');
    end;不要用Components,因为这样会包括不可视的组件
      

  4.   

    Var
      I : Integer;
    begin
      for I := 0 to Form.Componentcount - 1 do 
        if Form.Components[I] is TEdit then
           if TEdit(Form.Components[I]).text = '' then //就这样;
              begin
                //do something
              end
    end;
      

  5.   

    var
      i:integer;
    begin
    with Form1 do
      for i:=0 to ControlCount-1 do
        if Controls[i] is TEdit then
          if (Controls[i] as TEdit).Text='' then
            ShowMessage((Controls[i] as TEdit).Name+'为空');
    end;看起来更明了
      

  6.   

    这样可以不可以?虽然有点麻烦if (edit1='' )or (edit2='')or ....用或语句不知道你满意不满意
      

  7.   

    如果你把Edit放在其他容器上,用上面的方法就不行了,呵呵
      

  8.   

    EDIT自己就可以是数组,干吗还要用Components??(sender as TEdit).tag 跟你这个要求没关系,是判断控件的你必须要每个都判断
      

  9.   

    把Edit控件的Name设为有规律的,类似如下:for i:= 1 to 15 do
    begin
      if TEdit(FindComponent('Edit'+IntToStr(i))).Text='' then
        begin
          ShowMessage('不能为空!');
          Exit;
        end;
    end;
      

  10.   

    Edit又不是动态生成?怎么会是数组我上面用的是Controls数组,不是Components数组,如果窗体上有大量不可视的组件,会判断很多无效元素如果不是特殊需要,控件名都是默认的控件名,不做修改,不利于程序后期维护
      

  11.   

    onexitif (sender as Tedit).text='' then
      (sender as TEdit).tag:=1
    else
      (sender as TEdit).tag:=0;if (edit1.tag+edti2.tag+..+edit10.tag)>0 then
      showmessage('空的');
      

  12.   

    我觉得15个if最好了,因为15个edit说明输入的内容很丰富,种类也多。如果仅仅检测是否为空肯定不够,比如有些可能是数字就要检测是否是数字,有些可能是特定的字符,都要挨个检测,这样程序简单,清晰,易维护,何乐而不为。
      

  13.   

    Var
      I : Integer;
    begin
      for I ;= Form.Componentcount - 1 do 
        if Form.Components[I] is TEdit then
           if TEdit(Form.Components[I]).text = '' then;
              begin
              end
    end;
    这种方法好点 写上注释阿省了看不懂