Ian Branch 127 Posted October 7, 2022 Hi Team, When creating a form in code.. i.e. MyForm := TMyForm.Create(xxx); If the code the creation is happening is in the MainForm's code, what are the Pros and Cons of xxx being 'Application.MainForm', 'Self' and 'Nil' please?? Does it matter?? Regards & TIA, Ian Share this post Link to post
Uwe Raabe 2057 Posted October 7, 2022 Sorry, but I don't understand your question. Share this post Link to post
Ian Branch 127 Posted October 7, 2022 Hi Uwe, Apologies. In my MainForm I create subforms depending on the menu selection. I currently use the format MyForm := TMyForm.Create(nil); Just an old habit/practice. I have seen variously 'Application.MainForm', 'Self' and 'Nil' in the .Create(). I am curious, if the subform creation is from the MainForm's code, what are the Pros and/or Cons of using 'Application.MainForm', 'Self' or 'Nil' in the .Create()?? Is Application.MainForm the same as Self in this context? HTH. Regards, Ian Share this post Link to post
Attila Kovacs 629 Posted October 7, 2022 you could start here https://docwiki.embarcadero.com/RADStudio/Sydney/en/Components_and_Ownership Share this post Link to post
Uwe Raabe 2057 Posted October 7, 2022 Application.MainForm is set with the first TForm created with Application.CreateForm. Share this post Link to post
Ian Branch 127 Posted October 7, 2022 Hi Team, Thank you for your inputs. This link gave me the insight I was after. https://www.thoughtco.com/tform-createaowner-aowner-1057563 Regards, Ian Share this post Link to post
Remy Lebeau 1397 Posted October 8, 2022 23 hours ago, Ian Branch said: I am curious, if the subform creation is from the MainForm's code, what are the Pros and/or Cons of using 'Application.MainForm', 'Self' or 'Nil' in the .Create()?? The only thing that matters is whether you assign a nil Owner (ie, you are responsible for freeing the sub-Form when you are done using it) or assign a non-nil Owner (ie, the Owner will free the sub-Form when the Owner itself is freed). WHO the Owner is when non-nil is largely irrelevant, as long as the Owner outlives the usage of the sub-Form. 23 hours ago, Ian Branch said: Is Application.MainForm the same as Self in this context? Yes. Share this post Link to post