procedure from1.button1Click(Sender: TObject);
if combobox1.Items.Indexof(combobox1.Text) < 0 then
begin
  with table1 do
  begin
    first;
    while fieldbyname('nationality'.AsString <> '' do next;
    if eof then    //如果到了末尾,就添加一行//
      append
    else
      edit;
    fieldbyname('nationality').asstring:=combobox1.text;
    post;
    combobox1.Items.Add(combobox1.Text);
  end;
end;
end;

解决方案 »

  1.   

    错误修正:
    第7行改为:
    while not eof and fieldbyname('nationality'.AsString <> '' do next;
      

  2.   

    哦,else下面的操作应该是edit,我误写了,嘻嘻。
    万王之王,你看到我写的程序,是不是要发疯啦,嘻嘻。
    对了,我的表中是没有空白行了,movingboy,谢谢你哦。
                                                            
      

  3.   

    你可以用一个combobox定位记录,另一个操作!用一个不好操作!
      

  4.   

    你不要判断是否已经到了最后一行,应该判断当前行的nationality值是否为空,若为空,则将输入内容赋给nationality字段,否则继续循环。
    还有一个问题:当出现如下情况时
                  edulevel      nationality 
                    高中            中国
                    本科            法国
                    硕士            中国
    此时在combobox1中填入'法国',再按button1的话,数据表会怎么变?你有想过吗?
      

  5.   

      其实我现在要做的就是新增员工,通过combobox1来选择他的国籍,如果combobox1中没有适合他的内容,就在框中输入,然后,我要是按下“新增”按钮后,员工数据表中就有了他的记录,而专门记录combobox中内容的表(名字叫comboxfield中,国籍字段里也应该加入了新增的内容),以后再通过combobox1选择的话,就有这个新国籍了。我仅仅是列举了一个combobox,其实我的界面上有很多combobox控件呢,比如学历、民族、政治面貌等都用combobox框显示以供选择的,而各个combobox的信息来源就是数据表combofield中各个字段的内容,你这下明白了吧。呜呜,好复杂呀
      

  6.   

    哦,我刚接触delphi哦,用他做毕业设计呀,所以很多地方都很生疏的,你不要笑话我哦。