unit uDataModuleBase;

interface

uses
   Classes;

type
  IDataModuleBase = interface
    ['{0377C83C-5C68-47CD-97A6-A764746CD2B1}']
  end;

  TDataModuleBase = class(TDataModule, IDataModuleBase)
  private
    FRefCount: Integer;
  protected
    function QueryInterface(const IID: TGUID; out Obj): HResult; override; stdcall;
    function _AddRef: Integer;                  stdcall;
    function _Release: Integer;                 stdcall;

  public
    property RefCount: integer read fRefCount write fRefCount;

  end;

implementation


{$R *.DFM}

// Set an implicit refcount so that refcounting
// during construction won't destroy the object.

function TDataModuleBase.QueryInterface( const IID: TGUID; out Obj): HResult;
begin
 if GetInterface(IID, Obj)
    then Result := 0
    else Result := E_NOINTERFACE;
end;

function TDataModuleBase._AddRef: Integer;
begin
  Inc(fRefCount);
  Result := fRefCount;
end;

function TDataModuleBase._Release: Integer;
begin
  Dec(fRefCount);
  Result := fRefCount;
  if fRefCount = 0 then Destroy;
end;


end.
