Board index » delphi » Word 97 and Delphi 5 - restart word

Word 97 and Delphi 5 - restart word

Is there a way to restart Word if the user closes it
while your Delphi application is running?

(ie avoiding "the RPC is not available" message.)

Thanks in advance

 

Re:Word 97 and Delphi 5 - restart word


<<John Chapman:
(ie avoiding "the RPC is not available" message.)

Quote

You need to make sure you know when the user has closed
Word, and then call the Disconnect method of any connected
Word components you're using. You can just use the
TWordApplication's OnQuit event for that.

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

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Word 97 and Delphi 5 - restart word


Thanks for the swift response
Is there a simple example somewhere please?

I can close and restart word under program control but if the user closed
word I get the error message

Setup is as follows:

I have a twordapplication component
in the onquit event
 Wordapplication1.disconnect

Properties:
Autoconnect is false
Autoquit is false
Connectkind ckrunningornew

I'm not using any other word components.

I have a start word button

 wordapplication1.connect;  {starts word}
 wordapplication1.visible:=true; {displays it}

I have a close word button

 WordApplication1.quit;
   wordApplication1.disconnect;

I'm working with Word 97 on W2K

Thanks in advance for any comments.

Re:Word 97 and Delphi 5 - restart word


Is there a simple example available please:

My sample program:

I have a twordapplication component:
(no other word components used)

OnQuit event
 WordApplication1.quit;
   wordApplication1.disconnect;
end;

Properties
Autoconnect False
Autoquit False
ConnectKind ckRunningorNew

Start word button:

  wordapplication1.connect;  {starts word}
  wordapplication1.visible:=true; {displays it}

Close Word button:

   WordApplication1.quit;
   wordApplication1.disconnect;

I can start and close word multiple times under program control.
However, I cannot restart if the user closes word.

Environment
Delphi 5,Word 97, Win2K

Re:Word 97 and Delphi 5 - restart word


<<John Chapman:
I'm working with Word 97 on W2K

Quote

I think the Word version may be your problem - there's a
bug in Word97 that stops the OnQuit event from being fired
if there are no open documents. To solve this you can use
WaitForSingleObject to find when Word closes - people have
to use this technique with Excel, which has no OnQuit
event. I wrote a little freeware component to do this for
you in a thread, which you can download from
http://www.djpate.freeserve.co.uk/AutoOffc.htm

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

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Word 97 and Delphi 5 - restart word


Thanks Deborah, you correctly identified the problem.

If Word 97  is closed by the user with a document open, Delphi can restart
Word.

I will give your component a test and let you know the outcome.

Other Threads