|
OWLNext 6.32
|
The factory template classes create callback code for both automated and non automated Doc/View and non-Doc/view ObjectWindows applications. Use these factory template classes to make objects for embedding and linking. (That is, when an application object needs to be embedded within another container, the callback function is responsible for creating the embedded object.) Depending on the template arguments passed to the factory class, you obtain different kinds of factories designed to create the object you need. All the templetized classes, however, assume that the application is using a global AppDictionary (the application's dictionary), and a global Registrar (the TOcRegistrar pointer that manages registering the application in the database).
ObjectWindows includes several factory template classes, divided into two main categories: those designed for Doc/View applications and those designed for non-Doc/View applications. Although all these classes contain the same functions, they are designed to create different types of objects.
The factory class hierarchy chart illustrates the inheritance relationship among these classes. Each class takes three arguments: the application class, the automation class, and the Doc/View class. The arguments indicate whether or not the application is a Doc/View application and whether or not the application is automated. The factory classes and their definitions include the following four classes.
TOleDocViewFactory class for Doc/View, non-automated, OLE components template <class T> class TOleDocViewFactory : public TOleFactoryBase<T, TOleFactoryDocView<T, TOleFactoryNoAuto<T>>>{ }; TOleDocViewAutoFactory class for Doc/View, automated OLE components template <class T> class TOleDocViewAutoFactory : public TOleFactoryBase<T, TOleFactoryDocView<T, TOleFactoryAuto<T>>>{ }; TOleFactory class for non-Doc/View, non-automated, OLE components template <class T> class TOleFactory : public TOleFactoryBase<T, TOleFactoryNoDocView<T, TOleFactoryNoAuto<T>>>{ }; TOleAutoFactory class for non-Doc/View, automated OLE components template <class T> class TOleAutoFactory : public TOleFactoryBase<T, TOleFactoryNoDocView<T, TOleFactoryAuto<T>>>{ };
For either a Doc/View or a non-Doc/View application, you need to register your application in your OwlMain function. The argument to TOcRegistrar (in this case, TOleFactory<TDrawApp>) constructs an object and converts it to a TComponentFactory type, using the operator TComponentFactory to create a function pointer. In reality, the object is never created because all the factory class's functions are static.
Pass your application object derived from TApplication as the parameter to TOleFactory, as the following code from STEP15.CPP illustrates:
int OwlMain(int /*argc*/, char* /*argv*/ []) { try { Registrar = new TOcRegistrar(AppReg, TOleFactory<TDrawApp>(), TApplication::GetCmdLine()); if (Registrar->IsOptionSet(TOcCmdLine::AnyRegOption)) return 0; //If this is a normal exe server, run the application now; otherwise, // wait until the factory is called. return Registrar->Run(); }
In general, the following steps, illustrated in the Factory Class Callback Flowchart, show the steps each factory class follows in the default callback code:
The factory can be called back to walk through this process several times:
1.7.4