Smart Transaction Manager lazarus / 16-Databases ---------------------------------------------------------------------- DeBritto · 2016-06-06 00:38 Hi everyone, I'm starting to deal with transactions in my app and I've found this code at this web site (From: http://delphi.xcjc.net//viewthread.php?tid=48818). But unfortunately I still doesn't know how to change it to work in Free Pascal/Lazarus using the basic components. I'm using Firebird 2.5 as database. I thought that this code could be usefull not only for me. Could anyone help me translate it to work in Free Pascal/Lazarus? Other question, do you think that this logic works well? {Smart Transaction Management with Firebird/Interbase} Add the following functions to your main datamodule (dmMain) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i public    procedure OpenQuery(Q: TIBQuery; AForceRB: boolean = false);    procedure ExecQuery(Q: TIBQuery; AForceRB: boolean = false; FAutoCommit: boolean = false); //and in the implementation: procedure TdMain.ExecQuery(Q: TIBQuery; AForceRB, FAutoCommit: boolean);begin  if Q.Transaction.InTransaction then  // only rollback if active    if AForceRB then      Q.Transaction.Rollback; if not Q.Transaction.InTransaction then    Q.Transaction.StartTransaction; try Q.ExecSQL; except  on E:Exception do  begin    if Q.Transaction.InTransaction then      Q.Transaction.RollBack;  Assert(false, 'An error has occurred while executing the query '+Q.Name+'.'#13#13'Errormessage: '+E.Message); end; if FAutoCommit then    Q.Transaction.Commit;end; procedure TdMain.OpenQuery(Q: TIBQuery; AForceRB: boolean);begin  if Q.Transaction.InTransaction then    if AForceRB then      Q.Transaction.Rollback; if not Q.Transaction.InTransaction then    Q.Transaction.StartTransaction; try Q.Open; except  on E:Exception do  begin Assert(false, 'An error has occurred while opening the query '+Q.Name+'.'#13#13'Errormessage: '+E.Message); end; end; In order to use these function think like this: Some form, getting data to fill listbox: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure UpdateListbox;begin  qGet.SQL.Text:= 'SELECT NAME FROM CUSTOMERS ORDER BY CITY'; dMain.OpenQuery(qGet, true); // force rollback before opening - most recent data is wanted. while not qGet.Eof do  begin    lbCustomers.Items.Add(qGet.Fields[0].AsString);    qGet.Next;  end; qGet.Transaction.Commit;end; ---------------------------------------------------------------------- valdir.marcos · 2017-04-16 23:44 More than 10 months have passed, just as a curiosity, have you found a solution for you? ---------------------------------------------------------------------- valdir.marcos · 2017-04-16 23:48 Quote from: DeBritto on June 06, 2016, 02:38:07 amSmart Transaction Management with Firebird/Interbase http://delphi.xcjc.net//viewthread.php?tid=48818). ... do you think that this logic works well? No. If you are working with transactions on RAD, you'd better be explicit using try/except and commit/rollback whenever they are necessary. That's make you code clear for you and for future maintain.