窗口上的14个combobox(combobox1-combobox14)每个combobox都对应一个edit
(edit3-edit16)  combobox1 <==> edit3....combobox14 <==> edit16 
edit中只能有数字
在一个插入按钮的click事件中
如果有一个combobox选了值而对应的edit却没有数值,那就显示“输入错误”
如果有一个combobox没选值而对应的edit却有数值,那也显示“输入错误”
通过以上判断后,因为edit的值插向的字段是smallint类型的,所以不能为空。
这个各位前辈看着办吧。你们当然会有自己的招。
我的想法是把它们的值赋为零。
**不过要注意,可别把合法的edit的值也变为零了哦。

解决方案 »

  1.   

    你可以用self.Component[i],它表示该窗体上第i个控件,你可以根据Combobox和edit的生成顺序将它们和相应的序号“i”对应起来。
    比如Combobox1..14=>1..14
    edit3..16=>15=>28
    通过if (self.Component[i] is TEdit) then TEdit(self.Component[i] as TEdit).Text,和if (self.Component[i] is TCombobox) then TCombobox(self.Component[i] as TCombobox).Text进行访问。
      

  2.   

    也就是说combobox和edit,在插入字段时都不许为空?insButton.click(...)
    if combobox1.items<>'' and edit3.text<>' then
      inseart
    else 
      showmessage(‘输入错误’);
    if .........
    if ......
    if ........
      

  3.   

    程序不写了
    给你个提示
    用findcomponent
    比如说你点了combobox1,那你就去检查findcomponent('edit3')的属性
    showmessage((findcomponent('Edit3') as TEdit).Text);
    你只需要知道是哪个combobox被选中就行了
    然后写一个通用函数
      

  4.   

    var
      i:integer;
    begin
     for i:=0 to form1.ComponentCount-1 do
        if (form1.FindComponent('combobox'+inttostr(i+1)) as   Tcombobox).text<>'' then
        if form1.FindComponent('edit'+inttostr(i+1)) as Tedit).text='' then
        showmessage('输入错误!');
        ......
      

  5.   

    16个combobox中的分组,用tag区分,14个为1,另外的分0
    adoquery.open;
    while not adoquery.eof do 
    begin
      for i:=0 to self.ControlCount-1 do 
      begin
         if self.controls[i].className='TComboBox' then 
         begin
            if TComboBox(Self.controls[i]).tag=1 then 
             TComboBox(Self.controls[i]).items.add(adoquery.fields[0].asstring);     end; 
       end;
       adoquery.next;
    end;
      end;
    end;
      

  6.   

    把combobx的tag和对应的edit的tag设置为同一个
    别的你就按着上面的代码变化一下
      

  7.   

    把combobx的tag和对应的edit的tag设置为同一个如果有一个combobox选了值而对应的edit却没有数值,那就显示“输入错误”
    //index:为combobox的tag值
    procedure checkEdit(index:integer):boolean;
    begin
      for i:=0 to self.ControlCount-1 do 
      begin
         if self.controls[i].className='TEdit' then 
         begin
            if TEdit(Self.controls[i]).tag=index then 
             begin
             
             if TEdit(Self.controls[i]).text='' then 
               Result:=false
              else Result:=true;
              exit;    
             end;
         end; 
       end;end;
    //如果有一个combobox没选值而对应的edit却有数值,那也显示“输入错误”
    comboxbox与上类似,