BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Verifying availability of an IDispatch instance?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Jon Robertson
Guest





PostPosted: Thu Dec 02, 2004 8:27 pm    Post subject: Verifying availability of an IDispatch instance? Reply with quote



Is there any generic way to verify that the server-side of an IDispatch
instance is still available? I'm looking for something like this,
although cleaner than inc/dec a reference counter. Also, I'm not sure
whether this would verify the server was still available.

(warning, ad-hoc code):

function VerifyServerAvailable(MyInstance: IDispatch): Integer;
begin
Result := S_OK; // S_OK would indicate server is available

// Possible Error Results:
// RPC_E_DISCONNECTED: The object invoked has
// disconnected from its clients.
// RPC_S_OUT_OF_RESOURCES: Not enough resources are available
// to complete this operation.
// RPC_S_SERVER_UNAVAILABLE : The RPC server is unavailable.
// RPC_S_CALL_FAILED: The remote procedure call failed.
// RPC_S_CALL_FAILED_DNE: The remote procedure call failed
// and did not execute.
// etc

try
MyInstance.AddRef;
MyInstance.Release;
except
on E:EOleSysError do
Result := E.ErrorCode
else
raise;
end;
end;

Thanks!

--
Jon Robertson
Borland Certified Advanced Delphi 7 Developer
MedEvolve, Inc
http://www.medevolve.com
Back to top
Pascal Chapuis
Guest





PostPosted: Fri Dec 03, 2004 8:53 am    Post subject: Re: Verifying availability of an IDispatch instance? Reply with quote



"Re: Com Server Shut Down" ?
http://groups.google.com/groups?th=1f29e7964a9b86a9&seekm=754n8k%24nep8%40forums.borland.com#link2

Result:=(TComServerHack (ComServer)).ObjectCount>0);

Pascal

"Jon Robertson" <jon.robertson (AT) medevolve (DOT) dontspamme.com> a écrit dans le
message de news: 41af88b1$1 (AT) newsgroups (DOT) borland.com...
Quote:
Is there any generic way to verify that the server-side of an IDispatch
instance is still available? I'm looking for something like this,
although cleaner than inc/dec a reference counter. Also, I'm not sure
whether this would verify the server was still available.

(warning, ad-hoc code):

function VerifyServerAvailable(MyInstance: IDispatch): Integer;
begin
Result := S_OK; // S_OK would indicate server is available

// Possible Error Results:
// RPC_E_DISCONNECTED: The object invoked has
// disconnected from its clients.
// RPC_S_OUT_OF_RESOURCES: Not enough resources are available
// to complete this operation.
// RPC_S_SERVER_UNAVAILABLE : The RPC server is unavailable.
// RPC_S_CALL_FAILED: The remote procedure call failed.
// RPC_S_CALL_FAILED_DNE: The remote procedure call failed
// and did not execute.
// etc

try
MyInstance.AddRef;
MyInstance.Release;
except
on E:EOleSysError do
Result := E.ErrorCode
else
raise;
end;
end;

Thanks!

--
Jon Robertson
Borland Certified Advanced Delphi 7 Developer
MedEvolve, Inc
http://www.medevolve.com



Back to top
Jon Robertson
Guest





PostPosted: Fri Dec 03, 2004 3:55 pm    Post subject: Re: Verifying availability of an IDispatch instance? Reply with quote



Pascal Chapuis wrote:

Quote:
"Re: Com Server Shut Down" ?
http://groups.google.com/groups?th=1f29e7964a9b86a9&seekm=754n8k%24nep
8%40forums.borland.com#link2

Result:=(TComServerHack (ComServer)).ObjectCount>0);

Thanks, but this isn't what I'm looking for. This would be a server
side call, if I was writing the server object, to determine if any
clients are connected to me. (We already do something similar in our
DataSnap servers.)

I'm looking for a way to verify, from the client side, that a server I
am connected to (say Microsoft Word) still has a valid connection to
that server.

--
Jon Robertson
Borland Certified Advanced Delphi 7 Developer
MedEvolve, Inc
http://www.medevolve.com

Back to top
Pascal Chapuis
Guest





PostPosted: Sat Dec 04, 2004 10:08 am    Post subject: Re: Verifying availability of an IDispatch instance? Reply with quote

Client side would probably check the IUnknown.RefCount / ObjectCount
(?) property _published_ by the server ???

I'm also interested by a "generic way"...

Try...Except / RefCount / IMessageFilter / eventSink-callback ?

Automation expert Please could you show the right solution ?...

Pascal

"Jon Robertson" <jon.robertson (AT) medevolve (DOT) dontspamme.com> a écrit dans le
message de news:
Quote:

I'm looking for a way to verify, from the client side, that a server I
am connected to (say Microsoft Word) still has a valid connection to
that server.

--
Jon Robertson
Borland Certified Advanced Delphi 7 Developer
MedEvolve, Inc
http://www.medevolve.com



Back to top
Deborah Pate (TeamB)
Guest





PostPosted: Mon Dec 06, 2004 11:54 am    Post subject: Re: Verifying availability of an IDispatch instance? Reply with quote

< function VerifyServerAvailable(MyInstance: IDispatch):
Integer;
Quote:


Something to bear in mind is that Delphi calls IUnknown
methods on interfaces behind the scenes. So if the server
is no longer available, calling your function will probably
cause an exception that your try..except can't catch (and
not just because EOleSysError is for IDispatch errors).

You might use a variant to avoid behind-the-scenes
QueryInterfaces. This is not beautiful, but can be useful
in extremis:

function ServerAvailable(const Server: Variant): boolean;
begin
try
Server.GetTypeInfoCount;
Result := True;
except
on E: EOleSysError do
Result := E.Message = 'Member not found';
end;
end;

--
Deborah Pate (TeamB) http://delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html



Back to top
Jon Robertson
Guest





PostPosted: Mon Dec 06, 2004 8:03 pm    Post subject: Re: Verifying availability of an IDispatch instance? Reply with quote

Deborah Pate (TeamB) wrote:

Quote:
Delphi calls IUnknown
methods on interfaces behind the scenes.

You might use a variant to avoid behind-the-scenes
QueryInterfaces. This is not beautiful, but can be useful
in extremis:

Thanks Deborah!

PS Are you available for consulting? We've struggled with the same
COM/DCOM/Automation/IDispatch type problems for a while. We keep
trying something different, only to find new problems. I haven't asked
Management yet, but if you are available, I'd like to pursue it
further. Feel free to email me at jonrobertson at medevolve dot com.

--
Jon Robertson
Borland Certified Advanced Delphi 7 Developer
MedEvolve, Inc
http://www.medevolve.com

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.