How to create Delphi Object given its name and class name?

Question

Here is a link to a sample code implementing a user interface ( SDI, because MDI is confusing for many users ).

At the event : FormShow of the Main Form, I don't know how to restore the last embedded form, using its name and its Class name; any suggestions will be appreciated.

htp://rapidshare.com/files/139302098/UserInterfaceGoodPractices.rar.html

NB. the project uses only native delphi 2007 components.

Thanks.

Answer

Hello,

I did not follow/learn the above url. But maybe you need to store all of the created forms in a list (TList)?

Also, if you have a class-reference, you can always create a new instance of that class.
For example:
type TMyFormClass = class of TForm;
NewForm := TMyFormClass.Create();

In addition, any object has a ClassType property, so if you have an instance of a class, you can get its class- reference. Sometimes, it's only required to make a type-cast first such as:
ANewFormClass := TMyFormClass(ThisForm.ClassType);

The above examples are just what I usually do on my own applications. Hope that helps.

Sincerely,
Tom Barnet
HelpSmith 2.0. Help Authoring with Dynamic Styles.