unit uViewRegistryUtils;

interface

uses
  Classes, Forms, uClassRegistryUtils, uCustomView;

type
  IViewRegistry = interface (IComponentRegistry)
    ['{F49AE52F-47EC-42AF-8365-A09270E4B45D}']
    function CreateView(const aClassOrDisplayname: String;
      aOwner: TComponent = nil): TCustomView;
  end;


  TViewRegistry = class(TComponentRegistry, IViewRegistry)
  protected
    procedure ValidateMinAcceptableClass(var aMinAcceptableClass: TClass); override;
    function CreateView( const aClassOrDisplayname: String;
      aOwner: TComponent = nil ): TCustomView;
  end;

var
  ViewRegistry : IViewRegistry;

implementation

{ TViewRegistry }

function TViewRegistry.CreateView(const aClassOrDisplayname: String;
  aOwner: TComponent): TCustomView;
begin
  Result := CreateComponent( aClassOrDisplayname, aOwner ) as TCustomView;
end;

procedure TViewRegistry.ValidateMinAcceptableClass(
  var aMinAcceptableClass: TClass);
begin
  inherited;
  if not aMinAcceptableClass.InheritsFrom(TCustomView) then
    aMinAcceptableClass := TCustomView;
end;

initialization
  ViewRegistry := TViewRegistry.Create;

finalization
  ViewRegistry := NIL;
  
end.
