Contains a factory class for resources

This unit contains a factory class that provides an easy way to create resources of the right class.

Resource classes can be registered with so that the class knows how to create a resource of a specific type.

Base class for resource factory-related exceptions A resource class for a given type has already been registered

This exception is raised by class method RegisterResourceClass of when an attempt is made to register a class for an already registered type.

Factory class for resources

Resources are represented by descendants of TAbstractResource. Some applications don't need specialized resource classes, and a TGenericResource can be enough. On the other hand, sometimes it is required that a resource of a specific type is created with a more specialized class. This class provides a centralized point for the creation of resources.

holds a list of registered classes with an associated resource type. When it is requested to create a resource for a given type, it creates a resource of the class associated with that type. If no class matching that type is found, TGenericResource is used.

Usually each resource class registers itself in the initialization section of the unit in which it is implemented.

TAbstractResource TGenericResource
Registers a resource class

This class method registers a resource class for the given resource type.

If a class has already been registered for the given resource type, an exception is raised.

The type associated to the resource class The resource class to register Creates a new resource

This class method creates a new resource of the class associated with the given type, and sets its name and type based on the values passed as parameters.

If no class matching the given type is found, the resource is created with TGenericResource class.

TGenericResource
A new resource The type of the resource to create The name of the resource to create