Ian Branch 127 Posted June 1, 2022 Hi Team, D11.1.1. I have used the following construct in the calling/main form extensively.. // ChangesLogForm := TChangesLogForm.Create(self); // try ChangesLogForm.ShowModal; finally DBC1.CloseDataSets; FreeAndNil(ChangesLogForm); end; // for showing Modal forms. I now need to show several forms at the same time so I moved to this construct.. // ChangesLogForm := TChangesLogForm.Create(self); // ChangesLogForm.Show; // and added 'Action := caFree;' in the OnClose of the forms. Is this safe/correct/acceptable? Are there any -ve consequences? Regards & TIA, Ian Share this post Link to post
David Heffernan 2345 Posted June 1, 2022 It's quite possible there will be consequences. Impossible to say without knowing what your code looks like. Perhaps there are dependencies that require forms to be destroyed in a particular order. The erroneous finally block where you call that CloseDataSets method as well as destroying a form isn't a great sign. Share this post Link to post
Attila Kovacs 629 Posted June 1, 2022 If you are just asking about "'Action := caFree;", yes it's fine. Otherwise what David said. Non-modal needs different logic. Share this post Link to post
Ian Branch 127 Posted June 1, 2022 Thank you David & Attila, I just want to be sure. :-) The CloseDataSets was valid in the original code where only one sub-form was open at a time, however it isn't appropriate where multiple forms are going to be open. The relevant dataset is closed in the sub-form before the actual Close. Regards & Tks again, Ian Share this post Link to post
David Heffernan 2345 Posted June 1, 2022 1 hour ago, Ian Branch said: The CloseDataSets was valid in the original code where only one sub-form was open at a time It was never correct to put it in the same finally as lifetime management. Of course it won't matter if it never throws an exception. But it's basic sound practise not to put multiple unrelated tasks in a finally block. Share this post Link to post