Search code examples
delphidelphi-7

TOleContainer opening .tmp(word2016) documents Delphi7


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?


Solution

  • 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).