//函数,apply=true 保存,FALSE 不存
function TDmod1.DataSetApplyUpdates(DataSet: TDataSet; Apply: Boolean): Boolean;
begin
Result := True;
with TDBDataSet(DataSet) do
begin
if (State in dsEditModes) or UpdatesPending then
begin
if Apply then
begin
Database.ApplyUpdates([DataSet as TDBDataSet]);
{ Always call CancelUpdates to remove any discard changes }
CancelUpdates;
end
else
begin
if (APPLICATION.MessageBOX('数据还没有保存,您是否要放弃?', '提示',
MB_OKCANCEL or MB_ICONINFORMATION)=IDOK) then
CancelUpdates
else
Result := False;
end;
end;
end;
end;
//调用
procedure Tfrmuseclass.BtneditClick(Sender: TObject);
begin
if Dmod1.DataSetApplyUpdates(dmod1.USECLASSTab,True) then
Application.messagebox('存盘成功了!','提示',MB_OK or MB_ICONINFORMATION)
else
Application.messagebox('存盘失败了!','提示',MB_ICONERROR);
end;