I have a Delphi 10.4 application with 20+ forms that are created dynamically. There is a function that creates each form, like this:
Procedure SetForm(nForm : ShortInt);
Begin
Case nForm of
1: begin
If not Assigned(Form1) then
Application.CreateForm(TForm1, Form1);
Form1.Show;
End;
2: begin
If not Assigned(Form2) then
Application.CreateForm(TForm2, Form2);
Form2.Show;
End;
…
End;
End;
Can I create a generic function to create the forms, like this?
Procedure SetForm(nForm: ShortInt);
Var
xForm : TForm;
Begin
xForm := arrayForm[nForm]; // Array containing all forms;
if not Assigned(xForm) then
Application.CreateForm((some cast as TComponentClass), xForm);
xForm.Show;
end;
To complicate matters some, forms have a function that needs to execute before being shown, something like this:
xForm.SetUser(nUser);