Link to home
Start Free TrialLog in
Avatar of Jana618
Jana618

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of calinutz
calinutz
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jana618
Jana618

ASKER

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
Not really. The pages are the same. Maybe the way you look at them has changed... :)
Thanks for the points.