Solved

TWordApplication/TWordDocument with both Word2000 and WordXP

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need Delphi function to get Youtube video title 5 225
find a node in VST 2 63
Tviruailstringtree sort multi columns on header click 1 52
control image tags in a string ? 12 110
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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

911 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

21 Experts available now in Live!

Get 1:1 Help Now