How to dynamically invoke Create(Owner) on a component?
Posted on 2001-06-19
I have a frame TBaseFrame and two derived frames TDerivedFrameAlpha and TDerivedFrameBeta. In a form I put a TBaseFrame, but the TBaseFrame is abstract and will never be used. Only the derived frames. Because there will be a lot more derived frames than Alpha and Beta I want to use the Factory pattern to create derived frames. Like this:
function GetDerivedFrame(ClassName: String): TBaseFrame;
Now I have a detail question. Components need to be created with Create(Owner). Like this:
Button := TButton.Create(Self);
How to do this dynamically?
// Globals.ClassMap is a TList with registered classes
Clazz := Globals.ClassMap.Get('TButton');
Button := Clazz.NewInstance();
But this only calls:
Button := TButton.Create();