帮助看一段代码,谢谢!

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),但总是不成功。希望大家能帮我看一下,应该加到哪个位置。谢谢你们了。
[1739 byte] By [liyanchun-lyc] at [2008-2-13]
# 1
做一个判断看一看这个数据集是不是在编辑状态
if dbgrid1.datasource.dataset.state= dsedit then
dbgrid1.datasource.dataset.edit;
# 2
你这代码不够清楚,能说出核心么?
shizhoubo at 2007-10-22 > top of Msdn China Tech,Delphi,VCL组件开发及应用...