AsepRoro
AsepRoro

Reputation: 353

How to list all available form in delphi 7

i using delphi 7 and my project have many available form. i tried to execute application.component[i].classname to get all available form classname, but i only get list of created form classname.

is there way to get all available form classname in project to listbox?

Upvotes: 0

Views: 1920

Answers (1)

David Heffernan
David Heffernan

Reputation: 612934

You could use the built in class registry.

  • Register all your form classes by calling RegisterClass(TMyForm). Do this from an initialization section, typically that of the unit which defines the class.
  • When you want to recover the class from the registry, call FindClass passing the class name.
  • For safety, check that FindClass returns a class that inherits from TForm.
  • Finally create the form instance using either Application.CreateForm or just calling the Create virtual constructor of the class.

The instantiation looks like this:

var
  MyClass: TPersistentClass;
  Form: TForm;
....
MyClass := FindClass(ClassName);
if MyClass.InheritsFrom(TForm) then
  Form := TFormClass(MyClass).Create(AnOwner);

Upvotes: 2

Related Questions