1
votes

we are working with Delphi 7, SQL server 2008 and MS word 2003. now we are planning to migrate MS word 2003 to MS word 2016.

in our application we will load the document(BLOB field) from database and save it into .tmp file and then we will open the document using TOleContainer in Delphi7.

above process is working fine for .doc and it is not working for .docx. we are able to replicate the issue with below example

  1. create the .docx file
  2. open .docx file and enter some text and save and close
  3. rename the .docx to .tmp
  4. open the .tmp file using TOleContainer(Below Delphi code)

Delphi Code:

procedure TForm1.FormShow(Sender: TObject);
begin
  WordOleContainer.AllowInPlace := True;
  WordOleContainer.CreateObjectFromFile('F:\WordViewerTest\docx.tmp', False);
end;

when we run the application we are getting below error.if we click on open document is getting opened in another window, not in olecontainer. enter image description here

if i double click on .tmp file, it is opening with out any warning. if i use the above delphi code it is showing warning. how to make above code work?

1
Add to the registry what is described in step 2. of this topic for the *.docx file type (if *.docx has some unique file header; I believe it does).Victoria
@Victoria: it is not having any header ... its just plain .docx file with some text .DelphiLearner
I know. I meant from a binary point of view (if *.docx file has a unique binary signature). Step 2. of that topic is what you need (step 3. fails because of changed extension). The point is just how. The *.doc extension already has such entry in registry because for such files the GetClassFile returns specific class ID even if you change the extension (even on my computer, Office 2007, FYI).Victoria
@Victoria: Added that entry in registry and still we are facing same problem. OS is windows 2012 R2.DelphiLearner
You are not supposed to add registry entry shown in that topic. It's an example. You need to find a binary signature of *.docx and add entry for that one. Or in other words, you need to show the system a piece of *.docx file and associate it with Word application. That's the point.Victoria

1 Answers

0
votes

So long as *.docx file is actually a *.zip file from a binary point of view, there's no way to distinguish for the OLE binary pattern class search mechanism (described in the GetClassFile reference, step 2. of determining strategy) between those file types. If you registered a binary pattern for *.docx file, you would actually register *.zip files for opening by an application of your choice. Since then all the programs using OleCreateFromFile would open *.zip files in the application you've registered.

So to resolve your problem without any ambiguity in the system simply save the file with the proper *.docx extension and let OLE find the class by the file extension (step 3. of determining strategy).