Ian Branch 128 Posted September 27, 2021 Hi Team, Is there any difference between the following form creation methods?? Application.CreateForm(TReportsForm, ReportsForm); and ReportsForm := TReportsForm.Create(nil); Do either have an advantage over the other? Regards & TIA, Ian Share this post Link to post
David Heffernan 2353 Posted September 27, 2021 The former must be used to create the main form. Otherwise there's no need and you can just call the constructor. That's what I do. Use the Application method for the main form and call constructors directly otherwise. The other difference in these two snippets is the second one has no owner, but the former is owned by Application. Share this post Link to post
Ian Branch 128 Posted September 27, 2021 Tks David, I found the former in an older part of my code and couldn't remember the reason or need for it. I too use the latter form. Regards & Tks again, Ian Share this post Link to post
Remy Lebeau 1436 Posted September 27, 2021 2 hours ago, Ian Branch said: Is there any difference between the following form creation methods?? Calling a Form's constructor directly will just create the object immediately, and lets you specify the desired Owner. That is al it does. In VCL, there is not much difference to that. Calling TApplication.CreateForm() merely creates the specified class type, hard-coding the TApplication object as its Owner. But it also sets the TApplication.MainForm if it is not already assigned and a TForm is being created. Calling Create() directly does not do that. In FMX, there is little bit more of a difference. It also creates requested objects with TApplication as the Owner, but it also caches those requests until TApplication.CreateRealForms() is called, at which time all requested (and subsequent) objects are then physically created. It also does not set the TApplication.MainForm at all, there is a separate TApplication.CreateMainForm() call for that. Share this post Link to post