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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WiseGuyCommented:
Does the TestServer get started automatically?
0
WiseGuyCommented:
Does this problem occur in every server you make?
0
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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
philipleighsCommented:
Oh whoops, my last comment was meant to be an answer.

Cheers,
Phil.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rsajowaCommented:
Good work.
It does the job.

// Jo
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.