我想判断窗体内的edit,combobox组件是否为空值,如果为空,提示,我想用一个函数或过程,可是我写的不成功,不对,有哪位大侠能够写一个给小弟参考一下,写的全一点最好有注释,多谢了??

解决方案 »

  1.   

    var
      i : Integer;
    begin
      for i := 0 to Self.ControlCount -1 do
      begin
        if self.Controls[i] is TEdit then
        begin
          if TEdit(Controls[i]).Text = '' then
            showMessage(Controls[i].Name + ' is empty');
          continue;
        end;
        if self.Controls[i] is TComboBox then
        begin
          if TComboBox(Controls[i]).Text = '' then
            showMessage(Controls[i].Name + ' is empty');
          continue;
        end;
      end;
    end;
      

  2.   

    var
      i : Integer;
    begin
    for i := 0 to ComponentCount - 1 do
    begin
            if Components[i] is TEdit then
            begin
                if (Components[i] as TEdit).Text= '' then
                begin
                    ShowMessage((Components[i] as TEdit).Name +'is Null!')
                    Continue;
                end;
            end;
            if Components[i] is TComboBox then
            begin
                if (Components[i] as TComboBox ).Text= '' then
                begin
                    ShowMessage((Components[i] as TComboBox ).Name +'is Null!')
                    Continue;
                end;
            end;
    end;
    end;
      

  3.   

    如果第i个组件是TEdit,那么就没有必在再执行下面的代码,直接继续循环,判断下一个组件,我想第二个Continue加不加无所谓,因为我是从上面COPY过来的。
      

  4.   

    Allows the flow of control to proceed to the next iteration of for, while, or repeat statements.
      

  5.   

    var
      i : Integer;
    begin
      for i := 0 to Self.ControlCount -1 do
      begin
        if self.Controls[i] is TEdit then
        begin
          if TEdit(Controls[i]).Text = '' then
            showMessage(Controls[i].Name + ' is empty');
          continue;
        end;
        if self.Controls[i] is TComboBox then
        begin
          if TComboBox(Controls[i]).Text = '' then
            showMessage(Controls[i].Name + ' is empty');
          continue;
        end;
      end;
    end;
    continue 是继续得意思,如果continue后面还有别的代码的话,但碰到了continue 的话,就会跳过去即不执行后面的代码,而进行i+1操作
      

  6.   

    var i:Integer;
    begin
    If Edit1.Text='' then
    showmessage('Edit1 is empty!');
    for i:=0 to ComboBox1.Items.Count-1 do
    If ComboBox1.Items[i]='' then
    showmessage('ComboBox1 is empty!');
    end;
      

  7.   

    //数据必录项
    函数:
    function CheckIfInput(pcontrol:TEDIT; const pmsg:string):string;
    begin
        if length(pcontrol.text)=0 then
        begin
         application.MessageBox(pchar(pmsg+'为数据必录项,请您输入之!'),pchar('信息提示'),MB_OK);
         pcontrol.SetFocus ;
         checkifinput:='error';
        end;
    end;
    调用:
    if checkifinput(edit1,'姓名')='error' then exit;
      

  8.   

    以上过程声明时,TEdit改称TCombobox即可实现组合框的情况