procedure Twh_kfbm.DBGrid1ColExit(Sender: TObject);
 var
 sp : string ;
 i : integer ;
begin
if (DBGrid1.SelectedIndex =0) then
  begin
   if  trim(whdata.kfbm_temp.FieldByName('whouse_no').AsString) = '' then
     begin
       application.MessageBox('库房编码不能为空!' , '系统提示:',48) ;
       abort;
     end
     else begin
     //判断库房编号是否已经加过的了
        whdata.kfbm_temp.Edit ;
        whdata.kfbm_temp.Post ;
        whdata.kfbm_temp.Edit ;
        sp := trim(whdata.kfbm_temp.FieldByName('whouse_no').AsString) ;
        i := 0 ;
        if whdata.kfbm_temp.RecNo <> -1 then
          i := whdata.kfbm_temp.RecNo ;
        whdata.kfbm_temp.DisableControls ;
        whdata.kfbm_temp.First ;
        while not (whdata.kfbm_temp.Eof) do
         begin
           if (trim(whdata.kfbm_temp.FieldByName('whouse_no').AsString) = sp) and (whdata.kfbm_temp.RecNo <> i) then
             begin
              application.MessageBox('已经有相同的商品编号,请重新输入!','系统提示:',48) ;
              abort;
             end ;
           whdata.kfbm_temp.Next ;         end ;
          whdata.kfbm_temp.EnableControls ;        if i <> 0 then
         whdata.kfbm_temp.RecNo := i
      else
         whdata.kfbm_temp.Last ;
      end ;
      whdata.kfbm_temp.Edit;
   end
   else if (DBGrid1.SelectedIndex =1) then
   begin
     if trim(whdata.kfbm_temp.FieldByName('whouse_name').AsString) = ''then
     begin
       application.MessageBox('该记录没有输入库房名称,请补入!!' , '系统提示:',48) ;
       abort ;
     end;
    end;
 end;
不知怎的,每次运行有重复编码时,想修改这个重复编码,总是出现这样一个错误:数据集不在编辑或插入模式。我试着把这个语句加入程序里(dbgrid1.datasource.dataset.edit),但总是不成功。希望大家能帮我看一下,应该加到哪个位置。谢谢你们了。