Jump to content
Ian Branch

Form Creation difference??

Recommended Posts

Hi Team,

Is there any difference between the following form creation methods??

  Application.CreateForm(TReportsForm, ReportsForm);


  ReportsForm := TReportsForm.Create(nil);

Do either have an advantage over the other?


Regards & TIA,


Share this post

Link to post

The former must be used to create the main form. Otherwise there's no need and you can just call the constructor. That's what I do. Use the Application method for the main form and call constructors directly otherwise. 


The other difference in these two snippets is the second one has no owner, but the former is owned by Application. 

Share this post

Link to post

Tks David,

I found the former in an older part of my code and couldn't remember the reason or need for it.

I too use the latter form.


Regards & Tks again,


Share this post

Link to post
2 hours ago, Ian Branch said:

Is there any difference between the following form creation methods??

Calling a Form's constructor directly will just create the object immediately, and lets you specify the desired Owner.  That is al it does.


In VCL, there is not much difference to that.  Calling TApplication.CreateForm() merely creates the specified class type, hard-coding the TApplication object as its Owner.  But it also sets the TApplication.MainForm if it is not already assigned and a TForm is being created.  Calling Create() directly does not do that.


In FMX, there is little bit more of a difference.  It also creates requested objects with TApplication as the Owner, but it also caches those requests until TApplication.CreateRealForms() is called, at which time all requested (and subsequent) objects are then physically created.  It also does not set the TApplication.MainForm at all, there is a separate TApplication.CreateMainForm() call for that.

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