Just to add to 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 the function (despite its name) can be used to create other components. But only the first component that is a TForm and that is created succesfully, can be the main form.
And then a rant on global variables.
Yes globals are often wrong, but for an application object and a mainform object you can make an exception. Although you can omit the global for the mainform but you need to edit the dpr file yourself:
Change:
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 lost all global forms.