Skip to content

Commit 974b258

Browse files
Add AppCreateForm wrapper function.
1 parent 7b6a56d commit 974b258

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

Projects/Setup.dpr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ program Setup;
22

33
{
44
Inno Setup
5-
Copyright (C) 1997-2024 Jordan Russell
5+
Copyright (C) 1997-2025 Jordan Russell
66
Portions by Martijn Laan
77
For conditions of distribution and use, see LICENSE.TXT.
88
@@ -300,7 +300,6 @@ begin
300300
Application.MainFormOnTaskBar := True;
301301
InitializeSetup;
302302
MainForm := TMainForm.Create(Application);
303-
Application.CreateForm(TWizardForm, WizardForm);
304303
MainForm.InitializeWizard;
305304
except
306305
{ Halt on any exception }

Projects/Src/Setup.MainForm.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ procedure TMainForm.SetStep(const AStep: TSetupStep; const HandleExceptions: Boo
107107

108108
procedure TMainForm.InitializeWizard;
109109
begin
110+
WizardForm := AppCreateForm(TWizardForm) as TWizardForm;
110111
if CodeRunner <> nil then begin
111112
try
112113
CodeRunner.RunProcedures('InitializeWizard', [''], False);

Projects/Src/Setup.SelectLanguageForm.pas

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{
44
Inno Setup
5-
Copyright (C) 1997-2019 Jordan Russell
5+
Copyright (C) 1997-2025 Jordan Russell
66
Portions by Martijn Laan
77
For conditions of distribution and use, see LICENSE.TXT.
88
@@ -36,7 +36,8 @@ function AskForLanguage: Boolean;
3636
implementation
3737

3838
uses
39-
Shared.Struct, SetupLdrAndSetup.Messages, Shared.SetupMessageIDs, Setup.MainFunc;
39+
Shared.Struct, SetupLdrAndSetup.Messages, Shared.SetupMessageIDs,
40+
Setup.MainFunc, Shared.CommonFunc.Vcl;
4041

4142
{$R *.DFM}
4243

@@ -48,7 +49,7 @@ function AskForLanguage: Boolean;
4849
I, J: Integer;
4950
LangEntry: PSetupLanguageEntry;
5051
begin
51-
Application.CreateForm(TSelectLanguageForm, LangForm);
52+
LangForm := AppCreateForm(TSelectLanguageForm) as TSelectLanguageForm;
5253
try
5354
for I := 0 to Entries[seLanguage].Count-1 do begin
5455
LangEntry := Entries[seLanguage][I];

Projects/Src/Setup.Uninstall.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{
44
Inno Setup
5-
Copyright (C) 1997-2024 Jordan Russell
5+
Copyright (C) 1997-2025 Jordan Russell
66
Portions by Martijn Laan
77
For conditions of distribution and use, see LICENSE.TXT.
88
@@ -91,7 +91,7 @@ function TExtUninstallLog.ShouldRemoveSharedFile(const Filename: String): Boolea
9191

9292
procedure InitializeUninstallProgressForm;
9393
begin
94-
Application.CreateForm(TUninstallProgressForm, UninstallProgressForm);
94+
UninstallProgressForm := AppCreateForm(TUninstallProgressForm) as TUninstallProgressForm;
9595
UninstallProgressForm.Initialize(Title, UninstLog.AppName, ufModernStyle in UninstLog.Flags);
9696
if CodeRunner <> nil then begin
9797
try

Projects/Src/Shared.CommonFunc.Vcl.pas

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{
44
Inno Setup
5-
Copyright (C) 1997-2024 Jordan Russell
5+
Copyright (C) 1997-2025 Jordan Russell
66
Portions by Martijn Laan
77
For conditions of distribution and use, see LICENSE.TXT.
88
@@ -37,6 +37,7 @@ TWindowDisabler = class
3737
const
3838
EnableColor: array[Boolean] of TColor = (clBtnFace, clWindow);
3939

40+
function AppCreateForm(const AClass: TCustomFormClass): TCustomForm;
4041
procedure UpdateHorizontalExtent(const ListBox: TCustomListBox);
4142
function MinimizePathName(const Filename: String; const Font: TFont;
4243
MaxLen: Integer): String;
@@ -68,6 +69,22 @@ implementation
6869
MessageBoxCallbackParam: LongInt;
6970
MessageBoxCallbackActive: Boolean;
7071

72+
function AppCreateForm(const AClass: TCustomFormClass): TCustomForm;
73+
{ Creates a form, making it the main form if there isn't one already.
74+
Usage: AppCreateForm(TMyForm) as TMyForm
75+
This is a wrapper around Application.CreateForm, but with these advantages:
76+
- Safety: Returns a typed value instead of writing to an untyped parameter.
77+
- Safety: When used in an assignment statement: MyForm := AppCreateForm(...)
78+
the variable isn't modified until the form is fully constructed and the
79+
function exits. Application.CreateForm writes to its parameter, making the
80+
value public, before the form's constructor is executed, which could allow
81+
code outside the form to access the form before it's fully constructed.
82+
- When the result is casted with "as", it works with type inference.
83+
- When used in the .dpr, the Delphi IDE will never touch it. }
84+
begin
85+
Application.CreateForm(AClass, Result);
86+
end;
87+
7188
type
7289
TListBoxAccess = class(TCustomListBox);
7390

0 commit comments

Comments
 (0)