Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Owner = nil or Owner = Self on dynamic form creation?

ajoajo Posts: 40Member
Hello,

To conserve resources, I am setting up dynamic creation of forms that may not be used while my application runs. I am not sure what the best Owner is for a dynamically created form. With a nil Owner, there isn't the Notification method performance hit, but I think you have to use Free (or FreeAndNil) to get rid of it. I'd prefer to use the Release method to destroy the form object so that event handling on the dynamically created form is completed before the form is destroyed, but I understand that to use that I'd need to specify an Owner.

For example:
::
with TMyForm.Create(Self) do //Self = the calling form
try
ShowModal;
finally
Release;
end;

or

with TMyForm.Create(nil) do
try
ShowModal;
finally
Free; //or FreeAndNil(MyFormVar)
end;
::
Sorry for this elementary question; I'm relatively new to Delphi. Any opinions on this subject would be greatly appreciated. Thanks~

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hello,
    :
    : To conserve resources, I am setting up dynamic creation of forms that may not be used while my application runs. I am not sure what the best Owner is for a dynamically created form. With a nil Owner, there isn't the Notification method performance hit, but I think you have to use Free (or FreeAndNil) to get rid of it. I'd prefer to use the Release method to destroy the form object so that event handling on the dynamically created form is completed before the form is destroyed, but I understand that to use that I'd need to specify an Owner.
    :
    : For example:
    : ::
    : with TMyForm.Create(Self) do //Self = the calling form
    : try
    : ShowModal;
    : finally
    : Release;
    : end;
    :
    : or
    :
    : with TMyForm.Create(nil) do
    : try
    : ShowModal;
    : finally
    : Free; //or FreeAndNil(MyFormVar)
    : end;
    : ::
    : Sorry for this elementary question; I'm relatively new to Delphi. Any opinions on this subject would be greatly appreciated. Thanks~
    :
    :
    The Application is the owner of all the forms. So you should code the creation of forms like this:
    [code]
    TMyForm.Create(Application)
    [/code]

  • ajoajo Posts: 40Member
    : The Application is the owner of all the forms. So you should code the creation of forms like this:
    : [code]
    : TMyForm.Create(Application)
    : [/code]
    :
    :
    Thanks for the response. I just had one follow-up question: the application being discussed is relatively large. The primary form alone contains hundreds of components; it contains a PageControl with 13 TabSheets because it needs to be able to accomodate different types of documents. Also, there are around 35 additional forms contained in the project and a large DataModule (all of which may be added to). I understand it's safer to use an Application Owner because of automatic cleanup. However, (please correct me if I'm wrong) if I make the Owner of the form the Application, won't the Notification method be sent to every component and form owned by the Application each time a dynamically created form is and possibly cause a performance hit? I'm also concerned since the application is deployed via Citrix (potentially many people could be running the application at the same time on the same server--as well as other applications), could using Application as Owner impact processing on the server?

  • zibadianzibadian Posts: 6,349Member
    : : The Application is the owner of all the forms. So you should code the creation of forms like this:
    : : [code]
    : : TMyForm.Create(Application)
    : : [/code]
    : :
    : :
    : Thanks for the response. I just had one follow-up question: the application being discussed is relatively large. The primary form alone contains hundreds of components; it contains a PageControl with 13 TabSheets because it needs to be able to accomodate different types of documents. Also, there are around 35 additional forms contained in the project and a large DataModule (all of which may be added to). I understand it's safer to use an Application Owner because of automatic cleanup. However, (please correct me if I'm wrong) if I make the Owner of the form the Application, won't the Notification method be sent to every component and form owned by the Application each time a dynamically created form is and possibly cause a performance hit? I'm also concerned since the application is deployed via Citrix (potentially many people could be running the application at the same time on the same server--as well as other applications), could using Application as Owner impact processing on the server?
    :
    :
    I've checked the Notification procedure, and it only notifies menus, actionlists, and its own child components. So no matter how many forms there are, the only objects notified are the components on the newly created form and all the menus and actionlists that form depends on. So the only thing determining the load is the number of components on the forms you're creating at run-time. My advice is to just test it and see if it slows down too much or not.
Sign In or Register to comment.