Solved

TWordApplication/TWordDocument with both Word2000 and WordXP

Posted on 2004-10-17
3
6,313 Views
Last Modified: 2012-06-27
I have an application that is currently using TWordApplication and TWordDocument, and I use

WordDoc.ConnectTo(WordApp.Documents.Open(FileName,EmptyParam, EmptyParam,EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,EmptyParam, EmptyParam));

Of course, the number of parameters required for this function is different between Word2000 and WordXP... and using WordXP code on a machine with Word2000 installed causes the application to hang - very nasty.

I can easily check the version of Word installed in code, and then use the appropriate function, if I can make Delphi compile the code...

I tried placing both Word2000 and WordXP in the uses clause and typecasting:
  case GetInstalledWordVersion of
    Word2000:
        Word2000.WordDoc.ConnectTo
          (WordApp.Documents.Open(FileName, etc...
    WordXP:
        WordXP.WordDoc.ConnectTo
          (WordApp.Documents.Open(FileName, etc...
This gives an invalid typecast.

I tried placing the functions for Word2000 and WordXP in separate units so that I can place the appropriate version in the uses clause,
1) In interface units, but I got access violations when trying to use the functions... (when the component is placed on a form the first instruction is WordApplication.Connect; but in the interface unit I still got access violations when I tried WordApplication.Create; before WordApplication.Connect;)
2) Using the component on separate forms for each Word version. In this case Delphi automatically adds WordXP (because that's what I have installed on my machine) to the uses clause of the form  where I wish to use Word2000 every time I try to compile, so I cannot compile the application with this structure.

How can I:
1) use the TWordApplication and TWordDocument components in an interface unit
or 2) stop Delphi from automatically adding WordXP to the uses clause of the form (where I already have Word2000) ???
3) find another way?

Jana
0
Comment
Question by:Jana618
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
calinutz earned 500 total points
ID: 12336475
Never tryed this before, but can't you just use one version of Word? For example compile your project for Word2000. And try to run it on the computer with WordXP.
Or try to open your documents and work with them using the type library (early binding).
As in Deborah's pages of automation:
http://www.djpate.freeserve.co.uk/AutoWord.htm#WordStarting
0
 

Author Comment

by:Jana618
ID: 12336659
Using the one version compiled for WordXP my application hangs... even when held within a try...except clause.
The call to WordDoc.ConnectTo(etc...) compiled for WordXP will hang my application when used on a machine with Word 2000 installed. In this case the task manager will show a new WINWORD.exe process, but Word never completes the open process or returns control to the calling Delphi application... it's not very friendly.

I just tried out early binding and it looks to be fine so far. I compiled for Word2000 and it's opening documents fine on my WordXP machine, so I'll try it out on a few others... but Deborah also mentions some pretty drastic changes from Word97 to Word2000 so I might create separate units and check the installed Word version to be safe...

I seem to remember that when I started writing this part of the application there was a reason why I didn't use methods described by Deborah and turned to the servers...  I'm not sure but I think these pages have changed since I last looked ??

Thanks...
Jana
0
 
LVL 11

Expert Comment

by:calinutz
ID: 12344866
Not really. The pages are the same. Maybe the way you look at them has changed... :)
Thanks for the points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question