[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6417
  • Last Modified:

TWordApplication/TWordDocument with both Word2000 and WordXP

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
Jana618
Asked:
Jana618
  • 2
1 Solution
 
calinutzCommented:
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
 
Jana618Author Commented:
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
 
calinutzCommented:
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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now