Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Dynamic form creation
Fri, Jun 28 2013 8:51 AMPermanent Link

Christian Kaufmann

My application is structured in moduls. Every modul is a TForm with no
border and caption which I load dynamically as panel into the main
form. So far this works perfect.

procedure TFMain.FMainCreate(Sender: TObject);
begin
 AddModul(TFModulEntry.Create(Self));
 AddModul(TFModulRecord.Create(Self));
end;

The only disadvantage is, that all module forms are created on
startup. So I'm looking for a way to create my module forms
dynamically, based on the class / classname.

Does anybody find a solution for that? In Delphi I used class types
for this:

procedure TFMain.AddModul(AModulClass: TFormClass);

any suggestions?

cu Christian
Fri, Jun 28 2013 9:36 AMPermanent Link

Matthew Jones

I think I'd either do a simple case statement or the NeedFrmOptions type thing I
posted yesterday, where you call NeedEntry.Module before you do anything, and it
checks that the form is instantiated, or loads it. The key difference is that you
are not using the global variables, and so you need some other method for
determining if it has been done already.

/Matthew Jones/
Fri, Jun 28 2013 10:24 AMPermanent Link

Christian Kaufmann

>I think I'd either do a simple case statement or the NeedFrmOptions type thing I
>posted yesterday, where you call NeedEntry.Module before you do anything, and it

Ok, but then I need to implement that for each form. My intention is
something more generic like this:

 private
    FModuls : array of TForm;
    procedure AddModul(AModulClass: TFormClass);
 end;

procedure TMyForm.AddModul(AModulClass: TFormClass);
var
 ix : Integer;
begin
 ix := Length(FModuls);
 SetLength(FModuls, ix + 1);
 FModuls[ix] := AModulClass.Create(Application);
end;

procedure TMyForm.DoCreate;
begin
 AddModul(TFMyModule1);
 AddModul(TFMyModule2);
end;

cu Christian
Fri, Jun 28 2013 11:22 AMPermanent Link

Matthew Jones

I realise that would be better, but it may not be possible. If you could delay-load
them, then it would serve you well as then you don't load modules that aren't
actually used.

/Matthew Jones/
Image