whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

46 Visitors Online


 
...show a TForm with its Classname?
Autor: Loïs Bégué
Homepage: http://www.begue.de
[ Print tip ]  

Tip Rating (3):  
     


{
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.

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners