VclObjectFactory.pas

Index

A Library for Creating VCL-Style Objects
(Objects derived from TObject)
Copyright (c) 2003 Early Ehlinger

Download

VclObjectFactory.zip

License

Gnu Lesser General Public License, v2.1 (Included in the Code)

Authors

  • Early Ehlinger early@ehlinger.com
  • Installation

    Somewhere on your include path, unzip VclObjectFactory.zip. A file should be placed into a folder called ResBCB:

  • VclObjectFactory.pas
  • Usage

    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" ) );
    

    Notes

    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.