...show a TForm with its Classname?

Author: Loïs Bégué
Homepage: http://www.begue.de

Category: VCL

{
Möchten Sie z.B einen Formular mit einer Prozedure initialisieren bzw.
anzeigen ohne Type-informationen oder classreferenzen übergeben zu müssen?
Dies geht sowohl im Programmcode als auch zur Laufzeit.

Dabei gilt z.B.: bei Formulare werden die von Delphi angelegten globalen
Variablen bzw. die automatische Erzeugung im Hauptprogramm überflüssig:

Die Anbindung der Units und die RegisterClasses(...) sind notwendig!!!
}

{
You may wish to initialise some descendant of a given class (runtime /
designtime) using a simple procedure but without passing Type
information of a specified class to it and thus stay flexible ?

You can deal with the global variable of your forms as you wish,
you'll never need them again...

You just need to bind your form units and to register your classes
(Delphi won't, if you delete the global vars).
}


uses
MyFormOne, MyFormTwo;

procedure ShowOneOfMyForm(FormClassName: string);
begin
with
TFormClass(FindClass(FormClassName)).Create(Application) do
try
ShowModal;
finally
Free;
end;
end;

{ Geben Sie z.B. "TMyFormTwo" in dem TEdit und clicken Sie auf dem Knopf }
{ How to use it? Give "TMyFormTwo" in a TEdit and click the TButton...}

procedure TForm1.btShowMyFormClick(Sender: TObject);
begin
//at runtime
ShowOneOfMyForm(InputEdit.Text);
// or directly in your code
ShowOneOfMyForm('TMyFormOneF');
end;

initialization
RegisterClasses([TMyFormOneF, TMyFormTwoF]);
end.

 

printed from
www.swissdelphicenter.ch
developers knowledge base