Jump to content
Ian Branch

nil v self in form create??

Recommended Posts

Hi Team,

What are the Pros & Cons, and preference, of using Nil v Self in something like..

MyForm := TMyForm.Create(nil);      //  Nil or self.
  //
  try
    MyForm.ShowModal;
  finally
    FreeAndNil(MyForm);
  end;
  //

Regards & TIA,

Ian

Share this post


Link to post

Nil is when you destroy it explicitly

Self is when you leave it until owner is destroyed

Share this post


Link to post

Regardless of how it affects the instance ownership, if the Form has Position=poOwnerFormCenter then the Owner should be specified Otherwise it will fall back to poMainFormCenter.

  • Like 2

Share this post


Link to post
On 5/21/2021 at 9:29 AM, Fr0sT.Brutal said:

Nil is when you destroy it explicitly

Self is when you leave it until owner is destroyed

That is like... 30% of the information needed to understand the concept.

 

VCL object management do work. And is properly documented.

 

 

 

Share this post


Link to post
17 hours ago, Dany Marmur said:

That is like... 30% of the information needed to understand the concept.

Well, I don't consider it effective talking about integrals in answer to question "2+2=?". Anyway these 30% is much greater than 0% in David's answer :D

  • Like 1

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

×