Event BeforeClose is not working lazarus / 16-Databases ---------------------------------------------------------------------- mangakissa · 2014-03-11 08:42 In my application I call TMyQuery.BeforeClose() to commit all transactions of the active table. But BeforeClose is never triggered. I created a small demo with a form, a main datamodule and a inherited datamodule with Tbufdatasets. They are giving the same result. It is tested in Lazarus 1.0.12/FPC 2.6.2 Windows 8.1 and  Lazarus 1.2.RC2/FPC 2.6.2 Windows vista. This could be the reason why I occasionally got on error from the debugger on the transactions, but I'm not sure. ---------------------------------------------------------------------- Zoran · 2014-03-11 10:23 This is strange indeed. If I put a Button on the main form, and call close from there: Quoteprocedure TForm1.Button1Click(Sender: TObject); begin   FDMMain1.BufDataset2.Close; end;, then before close event is triggered. But in OnDestroy event of the DataModule it is not! Please report this to bugtracker. Indeed this seems to be a bug. ---------------------------------------------------------------------- mangakissa · 2014-03-11 12:22 Bug reported:  0025850 ---------------------------------------------------------------------- LacaK · 2014-03-12 06:10 I am only guesing, but what is ComponentState of BufDataset ? Can you put in for cycle any test: if ...ComponentState = csDestroying then showmessage('Destroying state'); ? If it is in Destroying state then BeforeClose is skipped. ---------------------------------------------------------------------- mangakissa · 2014-03-12 09:06 Okay. TBufDataset.ComponentState = [csDestroying] will activate the showmessage. Delphi does similar to Lazarus. What's the reason BeforeClose is skipped in Destroy? If it nessesary to close datasets in onDestroy if they are active? ---------------------------------------------------------------------- Derit · 2014-03-12 11:44 Quote from: mangakissa on March 12, 2014, 10:06:41 amOkay. TBufDataset.ComponentState = [csDestroying] will activate the showmessage. Delphi does similar to Lazarus. What's the reason BeforeClose is skipped in Destroy? If it nessesary to close datasets in onDestroy if they are active? you can use assigned(BufDataset1) this check there or not BufDataset1