Best strategy for additional forms lazarus / 31-LCL ---------------------------------------------------------------------- codifies · 2012-09-12 08:54 With additional forms am I better letting all the forms auto create and hiding all but the "main" form, then showing and hiding the forms as needed, OR am I better not auto creating the forms and only creating them when I need them and then destroying them as soon as I've done with them? Which method is better, and why?  Are there situations where one method might be better but not at other times ? ---------------------------------------------------------------------- ludob · 2012-09-12 09:18 The main difference is that "create when needed and destroy always"starts with a fresh form. All properties are cleared and the OnCreate is executed every time. Showing/hiding forms has a memory; the form's state is kept. It depends on your app if that is needed/desirable or not. Auto create forms can slow down program start up if there are a lot of forms and memory usage is higher than "create when needed and destroy always". Create when needed can, for complex forms, give a visible delay in bringing up the new form. Personally I use "create when needed and destroy always" for modal forms because the life time of the form is very short and references to the form are very localised. For non modal-forms interaction between forms can become more complex if one or the other form sometimes exists and sometimes not. Again, that depends on your app. ---------------------------------------------------------------------- codifies · 2012-09-12 09:25 thanks, its interesting to here how other people handle these kinds of situations I take the point about small short lived modal dialogs are probably most appropriately  created / destroyed rather than shown/hidden. Is speed really that much of an issue in this day and age? are for example database driven forms particularly expensive in terms of time to create? ---------------------------------------------------------------------- ludob · 2012-09-12 10:08 QuoteIs speed really that much of an issue in this day and age? are for example database driven forms particularly expensive in terms of time to create?Depends on what you are showing in the form. A form that displays the fields of the current record in a sqlquery already opened in data module will take no time to create. Opening a form with a DBGrid and a few dblookups using large tables that are not already opened will obviously take much more time. Note that you could very well create such a form at start up but only open the datasets when the form is shown (mind the caveats with dblookups opening datasets when fields are bound mentioned in another thread). So the question on when to create the form should be dissociated from when to fill in the data on the form. ---------------------------------------------------------------------- KpjComp · 2012-09-12 10:57 I also create on demand. As well as making even App's with 50+ forms load instantly.  I tend to have multiple instances of the same Form,.. Eg,.. If say I had a form to show customer information, then I'm able to show more than just 1 customer's information at a time. ---------------------------------------------------------------------- Knipfty · 2012-09-12 13:10 Hi chris_c, I take the view of letting Lazarus create the forms automaticallly on application start up and then simply show/hide them as I go along while developing the app.  Once I am done, I then take a long hard look at the application and see if it make sense do take over the creation of forms or not. If I have a dozen forms, then I'm proabbly not saving much.  If Ihave 50+, then there may be some savings in terms of memory.  But it's always a trade off.  Creating and destroying forms takes more time than simply showing/hiding. Knipfty ---------------------------------------------------------------------- Leledumbo · 2012-09-12 15:07 I never really have a need for non-modal forms except the main form, everything is created on the fly. Form contents are filled from a data structure that's kept alive (or a database if the form shows database records). ---------------------------------------------------------------------- codifies · 2012-09-12 16:14 thanks guy's this is really useful feedback and interesting to see other peoples motivations / reactions to "problems" ---------------------------------------------------------------------- teos · 2012-09-24 21:05 The first I ran into when started with Delphi was that I spend hours of writing code to clear the form contents when showing a form. After that I got in trouble with memory because I had forms and datamodules with loads of data. The second issue was with multiple instances of the same table, horror to keep data up to date. All of that does not excist when you create a form when needed and free it after showing. Unless you really need a form with kind of persistent information. Saves lots of time and lots of bugs. ---------------------------------------------------------------------- johnkdevnull · 2012-09-25 07:27 Forms that are in use all the time, I let lazarus autocreate at the outset.  Ones that are rarely used, I create when needed. I've never had any issues of delays when creating a form.