Programming => General => Topic started by: Marion on July 29, 2021, 09:47:41 pm
Title: How to keep track of child forms
Post by: Marion on July 29, 2021, 09:47:41 pm
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?
Title: Re: How to keep track of child forms
Post by: winni on July 29, 2021, 10:13:23 pm
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
Title: Re: How to keep track of child forms
Post by: Marion on July 29, 2021, 11:45:14 pm
This is what I have done.
When I create a form I make the parent form the owner:
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.
I 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.