How to keep track of child forms lazarus / 21-General ---------------------------------------------------------------------- Marion · 2021-07-29 19:47 I have a project that has a main form, and can open any number of child forms. If someone wants to reopen an object that already has an open form I want to bring it to the front, otherwise, open a new form for that object. I have tried keeping a list of the forms but because the list exists the closed forms never gets freed. What is the best way to keep track of the child forms? ---------------------------------------------------------------------- winni · 2021-07-29 20:13 Hi! You dont need to keep track of your child forms if you dont create them dynamic. If you have a lot of child forms they are shown with FormX.show (and NOT with FormX.ShowModal). Form.Show behaves this way: * If it is not active it is activated and brought to front * If it is active but hidden by other Forms (or other apps) it is brought to Front. That is the whole secret. Winni ---------------------------------------------------------------------- Marion · 2021-07-29 21:45 This is what I have done. When I create a form I make the parent form the owner: 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 newform := TnewForm.Create(parentform); In the OnClose event of the form I set: 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 CloseAction := caFree; When I need to find a form I use the parent form's Components list and check for the type of form I want, when I find it I then check to see if it is the form with the right object. 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 for i := 0 to parentform.ComponentCount - 1 do  if parentform.Components[i] is TnewForm then    if TnewForm(parentform.Components[i]).Value = myvalue then      TnewForm(parentform.Components[i]).BringToFront; ---------------------------------------------------------------------- Remy Lebeau · 2021-07-30 15:20 Quote from: Marion on July 29, 2021, 09:47:41 pmIf someone wants to reopen an object that already has an open form I want to bring it to the front, otherwise, open a new form for that object. I usually just loop through the TScreen.Forms list looking if the desired Form already exists, if so then Show() it, otherwise create a new instance. Quote from: Marion on July 29, 2021, 09:47:41 pmI have tried keeping a list of the forms but because the list exists the closed forms never gets freed. Why would that be?  Objects are not reference counted, so just keeping a list of object pointers would not prevent those objects from being destroyed.  Closing a Form does not auto-destroy it, though.  You need to set CloseAction=caFree in the Form's OnClose event if you want that behavior.