Forum > Databases

rolling back all changes on a modal form

(1/3) > >>

codifies:
at the moment whenever I leave a component in a model "edit record" form, as soon as I move from one component to another it seems to be saving the changes immediately (I can even see the grid used for choosing the record changing in the main form)

rolling back the transaction seems to have no effect (when clicking a cancel button I added to close the form)

I want to be able to make a bunch of changes and then when the cancel button is clicked roll everything back to how it was when the form opened

madref:
Take a look at this code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm_Wedstrijd_Informatie.Wedstrijd_Annuleren;begin  Close;end;     // Wedstrijd_Annuleren procedure TForm_Wedstrijd_Informatie.Wedstrijd_Bijwerken;begin  if CheckInput = False then Exit;  Wedstrijd_BijwerkenDB;end;     // Wedstrijd_Bijwerken procedure TForm_Wedstrijd_Informatie.Wedstrijd_BijwerkenDB;begin  //Sla het op in de tabel  if TQ_Wedstrijd.State in [dsEdit, dsInsert] then  begin    TQ_Wedstrijd.Post;    TQ_Wedstrijd.ApplyUpdates;    if Form_Lint.Trans_RefereeDB.Active then      Form_Lint.Trans_RefereeDB.CommitRetaining;  end;end;     // Wedstrijd_BijwerkenDB       TQ_Wedstrijd is the query i use for the form to open.
And then I check the state of the query if it's in edit or insert (a new record). If so I am writing the changes.
This procedure I use when I am pressing the [OK] (Wedstrijd_Bijwerken).
If I press [Cancel] I just close the form (Wedstrijd_Annuleren).


So I have 2 different methods for closing the form.


Hope it brings you something.

codifies:
so are you using a separate query???

isn't it still going to update the record as soon as a component looses focus ?

madref:
My forms are all dependent on at least one query (in my case TSQLQuery) and a TDataSource from which the TDataSource.DataSet refers to my Query.


All fields that are in that form are TDB.... fields AKA if it's an edit field it's reference is TDBEdit.
The TDBEdit.DataField refers to a field in your query
The TDBEdit.Datasource refers to your TDataSource.


And then you can use what I wrote before

codifies:
try as I might I can't get the modal form to rollback, I've tried allsorts, even using zeos db components, but as soon as a component looses focus, it looks as its changing the dataset immediately and the rollback is a noop

I might even try a separate transaction / query for the modal form, or I might just end up filling in values from the current record when the modal form first shows, and use a separate query to post the data.... 

I don't remember any issues doing this with Delphi, but mind that was nearly two decades ago so I might be misremembering...!

Navigation

[0] Message Index

[#] Next page

Go to full version