Gnu Lesser General Public License, v2.1 (Included in the Code)
Somewhere on your include path, unzip VclObjectFactory.zip. A file should be placed into a folder called ResBCB:
Include VclObjectFactory.pas in a BCB project. When you compile it, a header file will be generated, VclObjectFactory.hpp.
#include <ResBCB/VclObjectFactory.hpp> std::auto_ptr< TComponent > component ( VclObjectFactory::CreateComponent( "TSomeComponentDerivative" , aOwner ) ); component->Parent = this; component->Visible = true; std::auto_ptr< VclObjectFactory::TVclObject > object ( VclObjectFactory::CreateClassByName< VclObjectFactory::TVclObject >( "TSomeClass" ) ); |
If you have a class derived from TObject that you want to construct via the VclObjectFactory, you *MUST* make it derive from VclObjectFactory::TVclObject instead and give it a virtual default constructor. Otherwise your constructor will not get called. Sorry, but that's how it is.
All classes *MUST* be registered to be constructed. For classes derived from TPersistent, you can use RegisterClass. For classes derived from VclObjectFactory::TVclObject, you MUST use VclObjectFactory::RegisterVclClass.