Jump to content
Registration disabled at the moment Read more... ×
Ian Branch

Application.MainForm v Self v Nil??

Recommended Posts

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

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

Application.MainForm is set with the first TForm created with Application.CreateForm.

Share this post


Link to post
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×