Simple process. I edit the table, maybe only 3 fields. Then press button to call SaveData(qryInventory_, True);
And this procedure is called. No extra bits of code anywhere. There is code in here to save state to a text file.
procedure SaveData(qry: TSQLQuery; bSave: Boolean);
var
sTrans, sQry, sDS: string;
begin
sQry := qry.Name;
// sDS := qry.DataSource.Name; // exception created.
if dmCommonData.transLedger.Active then
sTrans := ' transaction Is active.'
else
sTrans := ' transaction is NOT active.';
try
if DataState(qry) then
sDS := 'DS in dsEdit, dsInsert, ';
if dmCommonData.transLedger.Active then
SendToFile('Saving Data -> ',sQry + ' ' + sDS + sTrans);
if bSave then
begin
if DataState(qry) then // checks for dsEdit or dsInsert, returns true.
begin
qry.ApplyUpdates;
dmCommonData.transLedger.CommitRetaining;
end;
end
else
begin
qry.CancelUpdates;
if dmCommonData.transLedger.Active then
dmCommonData.transLedger.RollBackRetaining;
end;
except
on E: EDatabaseError do
begin
dmCommonData.transLedger.RollbackRetaining;
MessageDlg('Error', 'DataBase error: '+ E.Message, mtError, [mbOK], 0);
// InsertIntoLog('Data Rolled back. ',s, qry.UpdateSQL.Text);
end;
end;
end;