Where is the name "Basic Form" stored in Delphi?

What physical file stores the main form name for the Delphi application?

eg. MyApplication has a MyForm form, which is set as the "Main form" through the project settings. Where is the "Main Form = MyForm" information stored?

In the Delphi IDE, the "Basic Form" application is specified through the menu: Project | Options | Forms Project | Options | Forms Project | Options | Forms

The obvious file would be a .bdsproj or .dpr file, but there is nothing in any of them that indicates which form is the "main" one.

+3
source share
2 answers

This is in the project file (.DPR). The first call to Application.CreateForm () with the form as parameter defines the main form of the application.

Please note that TDataModule does not satisfy the above requirement; which is really useful, because you can auto-write a datamodule in front of your main form and then access this datamodule in the constructor of the main form.

+15
source

Just add Ken White's answer.

If you look at the source for CreateForm:

 procedure TApplication.CreateForm(InstanceClass: TComponentClass; var Reference); var Instance: TComponent; begin Instance := TComponent(InstanceClass.NewInstance); TComponent(Reference) := Instance; try Instance.Create(Self); except TComponent(Reference) := nil; raise; end; if (FMainForm = nil) and (Instance is TForm) then begin TForm(Instance).HandleNeeded; FMainForm := TForm(Instance); end; end; 

You see that a function (despite its name) can be used to create other components. But the main form can only be the first component, which is TForm and which is created successfully.

And then rant about global variables.

Yes, global variables are often erroneous, but you can make an exception for the application object and the main form object. Although you can omit the global value for the main form, you need to edit the dpr file yourself:

Edit:

 begin Application.Initialize; Application.CreateForm(TMyMainForm, MyMainFormGlobal); Application.Run end. 

To:

 procedure CreateMain; var mainform : TMyMainForm; begin Application.CreateForm(TMyMainForm, mainform); end; begin Application.Initialize; CreateMain; Application.Run end. 

And you have lost all global forms.

0
source

All Articles