unit uController;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Windows, ActiveX, Classes, ComObj, pAggregateDemo_TLB, StdVcl, uAggregatedObj;

type
  TController = class(TTypedComObject, IController)
  private
    FAggregatedObj : IAggInterface;
  protected
    function GetName(var sName: WideString): HResult; stdcall;
    function GetInnerName(var sName: WideString): HResult; stdcall;
    {Declare IController methods here}
  public
    Destructor Destroy; override;
  end;

implementation

uses ComServ;

destructor TController.Destroy;
begin
  FAggregatedObj := nil;
  inherited;
end;

function TController.GetInnerName(var sName: WideString): HResult;
begin
  if (FAggregatedObj = nil) then
    FAggregatedObj := TAggregatedObj.Create(Self);

  FAggregatedObj.GetInnerName(sName);
  Result := S_OK;
end;

function TController.GetName(var sName: WideString): HResult;
begin
  sName := 'I am Controller!';
  Result := S_OK;
end;

initialization
  TTypedComObjectFactory.Create(ComServer, TController, Class_Controller,
    ciMultiInstance, tmBoth);
end.
