troubleshooting Question

Dynamically creating forms ....

Avatar of bernani
bernaniFlag for Belgium asked on
Delphi
17 Comments1 Solution674 ViewsLast Modified:
Hi,

Your opinion woud be greatly appreciated.

I've got this procedure - in a separate unit - wich dynamically creates a form (named Form2 or Form3 ... FormN) when I call it in the main form:

Implementation of the procedure:

Procedure LoadTheForm(Name: String; T:TFormClass; Panel:TPanel);
var
  f : TFormClass;
begin
RegisterClass(T);
  try
    f := TFormClass(FindClass(Name));
    with f.create(Application) do
    begin
    Parent:= Panel;
    Align:= alClient;
    Show;
    end;
  except
    raise;
  end;
end;

I click on a button in MainForm (filled with a PanelControl with TabSheets. One of those TabSheet contains a panel (Panel1) which is intended to be the parent (container) for my Form2. Calls are done in this way:

LoadTheForm('TForm2',TForm2, Panel1);
LoadTheForm('TForm3',TForm3, Panel11);
....

Form2 contains only:

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:= caFree;
form2:= nil;
end;

My question: all seems correct and is perfectly working. I'd like to know if this could be achieved in another way - in a better way ?  

I need to use the statement in the procedure:

with f.create(Application) do

and can't use the statement

with f.create(self) do

Could you tell me if this last statment is possible ?

Thanks.

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 17 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros