给点提示并写FormCloseQuery事件中在更好些:
procedure TOrdeInfoFrm.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
var
lChoose: Longint;
begin
CanClose := True;
if (cdsOrde.State = dsEdit) or (cdsOrde.State = dsInsert) then
begin
lChoose := Application.MessageBox('定单数据仍在编辑中,是否退出?', '提示',
MB_YESNOCANCEL);
case lChoose of
ID_YES: cdsOrde.Post;
ID_NO: cdsOrde.Cancel;
ID_CANCEL:
begin
CanClose := False;
Exit;
end;
end;
end;
if (cdsOrdeItem.State = dsEdit) or (cdsOrdeItem.State = dsInsert) then
begin
lChoose := Application.MessageBox('定单明细数据仍在编辑中,是否退出?',
'提示',
MB_YESNOCANCEL);
case lChoose of
ID_YES: cdsOrdeItem.Post;
ID_NO: cdsOrdeItem.Cancel;
ID_CANCEL: CanClose := False;
end;
end;
end;