I am getting a false refcount of my OleAutoServer

Quote
> Hello,

> I created an Automation server and now I created a client wich uses
methods
> of the Server.
> My problem is that when I close the server I get a message that the
> Application has got active comobjects. Serveral Clients could be
associated
> with com object. When I chek the refcount it shows always 4 eventhough I
> created only once. I have attached the code of my server and client below.
> Can somebody advise me what I am doing wrong?

> Thanking in advance,

> Ahamed
> --------------Server----------------
> unit Unit1;

> interface

> uses
>   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
>   StdCtrls;

> type
>   TForm1 = class(TForm)
>     Button1: TButton;
>     Button2: TButton;
>     procedure Button1Click(Sender: TObject);
>     procedure Button2Click(Sender: TObject);
>   private
>     { Private-Deklarationen }
>   public
>     procedure SayHello;
>     procedure CloseApp;
>     { Public-Deklarationen }
>   end;

> var
>   Form1: TForm1;

> implementation

> {$R *.DFM}

> procedure TForm1.SayHello;
> begin
>   ShowMessage ('Hello');
> end;

> procedure TForm1.CloseApp;
> begin
>   Close;
> end;

> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   SayHello;
> end;

> procedure TForm1.Button2Click(Sender: TObject);
> begin
>   CloseApp;
> end;

> end.
> ----

> unit Unit2;

> interface

> uses
>   ComObj, ActiveX, TestApplication_TLB;

> type
>   TTestApplication = class(TAutoObject, ITestApplication)
>   public
>     procedure CloseApp; safecall;
>     procedure SayHello; safecall;
>     procedure Initialize; override;
>     { Protected-Deklarationen }
>   end;

> implementation

> uses ComServ, unit1, Dialogs, Sysutils;

> procedure TTestApplication.CloseApp;
> begin
>   Form1.CloseApp;
> end;

> procedure TTestApplication.SayHello;
> begin
>   Form1.SayHello;
>   ShowMessage ('RefCount: '+IntToStr (RefCount));
> end;

> procedure TTestApplication.Initialize;
> begin
>   inherited;
> end;

> initialization
>   TAutoObjectFactory.Create(ComServer, TTestApplication,
> Class_TestApplication_,
>     ciMultiInstance, tmApartment);
> end.

> ----

> unit TestApplication_TLB;

> //

************************************************************************
Quote
> //
> // WARNUNG
> //
> // -------
> //
> // Die Typen, die in dieser Datei deklariert sind, sind Daten einer
> Typbibliothek.
> // Wenn diese Typbibliothek explizit oder indirekt (via Verweis)  //
> // re-importiert wird oder  die Anweisung 'Aktualisieren' im Editor //
> // fr Typbibliotheken beim Bearbeiten der Typbibliothek aktiviert ist //
> // wird der Inhalt dieser Datei neu generiert und alle    //
> // manuellen ?nderungen gehen verloren.                           //
> //

************************************************************************
Quote
> //

> // PASTLWTR : $Revision:   1.11.1.75  $
> // Datei generiert aus 12.03.2001 11:52:18 aus der unten beschriebenen
> Typbibliothek.

> //

************************************************************************
Quote
> //
> // Typbibl.: C:\Ahamed\AutomationServer\Project1.tlb
> // IID\LCID: {5614DEA2-F882-4C7F-8F9F-A7896ADA8DA2}\0
> // Hilfedatei:
> // HilfsString: Project1 Bibliothek
> // Version:    1.0
> //

************************************************************************

- Show quoted text -

Quote
> //

> interface

> uses Windows, ActiveX, Classes, Graphics, OleCtrls, StdVCL;

> // *********************************************************************//
> // GUIDS deklariert in Typbibliothek. Folgende Pr?fixe wurden verwendet:
> //
> //   Typbibl.     : LIBID_xxxx                                    //
> //   CoClasses          : CLASS_xxxx                                    //
> //   DISPInterfaces     : DIID_xxxx                                     //
> //   Non-DISP interfaces: IID_xxxx                                      //
> // *********************************************************************//
> const
>   LIBID_TestApplication: TGUID = '{5614DEA2-F882-4C7F-8F9F-A7896ADA8DA2}';
>   IID_ITestApplication: TGUID = '{472623CC-8A1F-450C-A3D4-8A579E93D04F}';
>   CLASS_TestApplication_: TGUID =

'{04D9850A-BA7E-4366-A4EB-CF72F32C9829}';

- Show quoted text -

Quote
> type

> // *********************************************************************//
> // Forward-Deklarationen von Schnittstellen definiert in Typbibl.
> //
> // *********************************************************************//
>   ITestApplication = interface;

> // *********************************************************************//
> // Deklaration von CoClasses definiert in Typbibl.                     //
> // (HINWEIS: Hier wird jede CoClass ihrer Standardschnittstelle zugewiesen
> //
> // *********************************************************************//
>   TestApplication_ = ITestApplication;

> // *********************************************************************//
> // Schnittstelle: ITestApplication
> // Flags:     (4352) OleAutomation Dispatchable
> // GUID:      {472623CC-8A1F-450C-A3D4-8A579E93D04F}
> // *********************************************************************//
>   ITestApplication = interface(IDispatch)
>     ['{472623CC-8A1F-450C-A3D4-8A579E93D04F}']
>     procedure SayHello; safecall;
>     procedure CloseApp; safecall;
>   end;

>   CoTestApplication_ = class
>     class function Create: ITestApplication;
>     class function CreateRemote(const MachineName: string):
> ITestApplication;
>   end;

> implementation

> uses ComObj;

> class function CoTestApplication_.Create: ITestApplication;
> begin
>   Result := CreateComObject(CLASS_TestApplication_) as ITestApplication;
> end;

> class function CoTestApplication_.CreateRemote(const MachineName: string):
> ITestApplication;
> begin
>   Result := CreateRemoteComObject(MachineName, CLASS_TestApplication_) as
> ITestApplication;
> end;

> end.

> ------------ Client ------------------
> unit Unit1;

> interface

> uses
>   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
>   StdCtrls;

> type
>   TForm1 = class(TForm)
>     Button1: TButton;
>     Button2: TButton;
>     procedure Button1Click(Sender: TObject);
>     procedure Button2Click(Sender: TObject);
>   private
>     ol: Variant;
>     { Private-Deklarationen }
>   public
>     { Public-Deklarationen }
>   end;

> var
>   Form1: TForm1;

> implementation

> {$R *.DFM}
> uses ComObj;

> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   ol:= CreateOleObject ('TestApplication.TestApplication');
>   ol.SayHello;
> end;

> procedure TForm1.Button2Click(Sender: TObject);
> begin
>   ol.CloseApp;
> end;