COM Server Warning

The below is done using Delphi 4 and Windows NT SP 4.

If I create an Automation Object and then create a client that connects to the object via it's CoClass i.e.

TestServer := CoTestServer.Create;

When I terminate the Server I get the Standard COM Server Warning telling be that there are clients still atached and killing the server may make them fail, which is fair enough.  How do I stop this message appearing?

It sometimes happens even when the client is closed as-well.

I did not get this problem using Delphi 3 and Windows 95.

Can anyone help?????
WoodyJ3Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
philipleighsConnect With a Mentor Commented:
Oh whoops, my last comment was meant to be an answer.

Cheers,
Phil.
0
 
WiseGuyCommented:
Does the TestServer get started automatically?
0
 
WiseGuyCommented:
Does this problem occur in every server you make?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
WoodyJ3Author Commented:
I run the Server before I run the client.

And yes it does happen to all servers I create under Delphi4 and Windows NT.
0
 
WiseGuyCommented:
Did you install all Delphi 4 patches?
0
 
WoodyJ3Author Commented:
Yes the very latest.

Is there a way to suppress this message.?
0
 
vitomanCommented:
If you are using databases in your client (ClientDataSet connecting to a RemoteDataModule, for instance), when it connects (DCOMConnection1.Connected := true), the Server will automatically open for you and access the database that you "Active"-ated from your client.

If you have the line:

  TestServer := CoTestServer.Create;

in your Create Method of your Form, you might possibly be opening two instances of that Server.

When you close your application, make sure you disconnected from the server and your database, also.

  ClientDataSet1.Active := False;
  DCOMConnection1.connected := false;

My 2 cents. :-)
0
 
WoodyJ3Author Commented:
No, I'm not using any Database stuff.
0
 
philipleighsCommented:
Been there, done that! I know exactly what you mean. There is nothing strange about your server, nor your clients, but this message still appears.

(My case is that I had two apps where the user doesn't know that there is a server/client relationship. Just two separate apps. Seems unreasonable to the user to be prevented from closing one app before the other (the client (VC++) checks the server is alive before doing anything with it)), so this led to a hackamatic.

After digging around the Com*.pas units for days, the only solution I came up with was this (I'm ashamed and embarrased to admit to this by the way):

....FormClose(...
begin
    if EmbeddedApp and (ComServer.ObjectCount <> 0) then
      begin
        //In a roundabout way, set the com server object count to 0
        //so we don't get the "Ole Automation Warning" message
        ComServer.Free;
        ComServer := TComServer.Create;
      end;
end;

I've seen people go into a catatonic state of shock after seeing this code ;-), but I've never encountered any bugs or side effects as a result (ComServer gets freed when you say yes to the message anyway).

Cheers,
Phil.

BTW, EmbeddedApp is a global boolean, assigned in the DPR:
  EmbeddedApp := ComServer.StartMode <> smStandAlone;
0
 
WoodyJ3Author Commented:
Nice one.  I glad someone has come across the same problem.

Post the answer for the points.

Cheers

John. :-)
0
 
philipleighsCommented:
Hi John,

Glad you like it!  ;-)

Thanks for the points.

Cheers,
Phil.
0
 
WoodyJ3Author Commented:
You need to post an answer in order to get the points.

Cheers
John.
0
 
rsajowaCommented:
Good work.
It does the job.

// Jo
0
All Courses

From novice to tech pro — start learning today.