Jump to content
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×