3
votes

I'm working on a legacy Delphi 6 (Build 6.240, Update Pack 2) application that works fine on Windows XP and Office 2000 - 2003.

Our client now wants to be able to run the app on Windows 7 with Office 2010.

The code seems to still create the Word merged document successfully, and saves it to a BLOB field in the Oracle database, and can successfully re-open the document from the database in Word 2010.

The problem is that the application then needs to create a PDF version of the document (using PDF-XChange), so it uses OleContainer.SaveAsDocument to write the document to a temporary file on disk. Attempting to open this document in Word 2010 (or even Word 2003) displays a "File Conversion" dialog box to "select the encoding that makes your document readable". None of the options seem to make the document readable (and even if they did there would still be a problem as this is an automated process).

The OleConnection is established using CreateObject('Word.document.8', false) I have also tried other values instead of 8 - 9, 10, 11 and 14 cause an 'invalid class string' error while 12 or just 'Word.document' run but have the same effect as 8, ie the saved document cannot be opened in Word.

So, the question is - how can I save a Word document from an OleContainer in Delphi 6, on Windows 7 with Word 2010, in a format that can be re-opened by Word?

1
Stab in the dark: Are you possibly saving the temporary file with a docx extension but saving it in its current (doc) format? If that is the case then you are subsequently feeding Word a doc format file with a docx extension and it can't figure out which xml encoding to use?Marjan Venema
No, the file is being saved with a .doc extension. (Thanks for the suggestion, though)David Carle

1 Answers

0
votes

From what I can tell the OleContainer is unable to save .docx files. Always corrupts them. I got around the issue by using the OleObject variable of the container so I could access Words procedures directly. Below is an example:

OleContainer.OleObject.SaveAs(DocumentName);

OleContainer.OleObject.Saved := True;

I see that you mentioned that you are using .doc but hopefully this will help you anyway.