Mega Code Archive

 
Categories / Delphi / Examples
 

Create a form knowing the class name only

If you run into a situation, where you would like to create and show a form, but you know the class's name only, you need to use the functions FindClass: procedure ShowAnyForm(sFormClassName: string); var FormClassType: TFormClass; Form: TForm; begin // possibility #1 FormClassType := TFormClass(FindClass(sFormClassName)); Application.CreateForm(FormClassType, Form); Form.ShowModal; Form.Free; // possibility #2 Form := TForm(TComponentClass(FindClass(sFormClassName)).Create(Self)); Form.ShowModal; Form.Free; end;