title: Delphi - register a com server in the ROT
body: <p>I've created a  very small automation object (using delphi 7).
  It works at all, but I have problem to register it in the running object table so that I can use getActiveOleObject function to retrieve a running instance of the server.
  The problem is that the Initialize and Destroy events doensn't fire.</p>
  
  <p>EDIT:
  I've just noted that the <strong>initialize</strong> is fired when I create the application via createOleObject in an client application.</p>
  
  <p>EDIT2:
  Download the sample projekt <a href="http://shs-it.de/downloads/automationobject.7z" rel="nofollow noreferrer">here</a></p>
  
  <p>Here's the sourcecode:</p>
  
  <pre><code>unit mycomserver;
  
  {$WARN SYMBOL_PLATFORM OFF}
  
  interface
  
  uses
    ComObj, ActiveX, server_TLB, StdVcl, dialogs;
  
  type
    Tmyserver = class(TAutoObject, Imyserver)
    private
      FROTCookie: Longint;
    public
      procedure Initialize; override;
      destructor Destroy; override;
    protected
      procedure hello; safecall;
  
    end;
  
  implementation
  
  uses ComServ;
  
  procedure Tmyserver.Initialize;
  begin
    inherited;
    //Register object in ROT
    showmessage('Why the init event doesnt fire?');
    OleCheck(RegisterActiveObject(Self, CLASS_myserver, ActiveObject_Weak, FROTCookie))
  end;
  
  destructor Tmyserver.Destroy;
  begin
    // unegister object in ROT
    showmessage('And destroy event also doesnt fire...');
    OleCheck(RevokeActiveObject(FROTCookie, nil));
    inherited;
  end;
  
  procedure Tmyserver.hello;
  begin
    showmessage('hello its me the comserver');
  end;
  
  initialization
    showmessage('com server init works...');
    TAutoObjectFactory.Create(ComServer, Tmyserver, Class_myserver,
      ciMultiInstance, tmApartment);
  end.
  </code></pre>