Solved

TWordApplication/TWordDocument with both Word2000 and WordXP

Posted on 2004-10-17
3
6,208 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
  • 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 168
find a node in VST 2 47
SUM 2 INTEGER ARRAYS INTO 1 10 63
how to update exe applicatio from internet ? 6 41
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now