RAD Studio VCL Reference
TComObjectFactory Class

TComObjectFactory is the type of the class factory object used to instantiate a TComObject class.

TComObjectFactory = class(TObject, IUnknown, IClassFactory, IClassFactory2);
class TComObjectFactory : public TObject, public IUnknown, public IClassFactory, public IClassFactory2;

TComObjectFactory supports the IUnknown, IClassFactory, and IClassFactory2 interfaces. The IClassFactory interface is implemented by class objects associated with class identifiers (CLSIDs) for the classes that they instantiate. IClassFactory must be implemented for every object definition, so that objects of that type can be created. The IClassFactory2 interface is implemented by class factories for classes that need support for licensing. 

Class factories instantiate the COM classes specified by a registered class identifier (CLSID). Class factory objects are created automatically by the COM servers that contain the code for the class objects and their associated classes. When a class factory is created, the CLSID is specified in a parameter to the constructor of the class factory object. This CLSID indicates the type of object for which the class factory creates instances. 

Class factory objects can also be externally instantiated by directly calling the Windows API function CoCreateClassObject. The functions CreateComObject or CreateOleObject can also be called to instantiate a COM class. These functions indirectly use class factories to instantiate the classes. When creating multiple instances of a class that has a CLSID, however, it is more efficient to instantiate a class factory, obtain a pointer to its IClassFactory interface, and use its methods as needed. 

Class factories are managed on the server by a global class manager accessed using the ComClassManager function. This class manager maintains a list of class factories through which the factories are manipulated, usually according to the COM server that owns them. 

IUnknown, IClassFactory, IClassFactory2 


Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!