🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.pascal.delphi.misc
1 messages
1 total messages Started by Simon Thompson Sun, 10 May 1998 00:00
OLE Automation: to Word. WindowName, OLEContainer, saving, printing.
#330
Author: Simon Thompson
Date: Sun, 10 May 1998 00:00
115 lines
4700 bytes
Hi,

I have tried to find answers to these questions using DejaNews, and 
other Internet resources. I find similar questions, but no answers 
(that work). I have manged to make progress via this method. 

I am using Delphi 2 to Word to put an address from a database into a 
Word document. This is using Word 97, although the target machine is 
Word 95 so I am using WordBasic.

I can get most of what I want using OLE Automation. This gives the 
user the ability to save, and print the document. The document is 
created from a templeate that the user selects. The code I have been 
using to test is:

procedure TMainForm.word95ButtonClick(Sender: TObject);
begin
  openDialog.initialDir := extractFilePath(application.exename);
  if openDialog.execute then begin
    StatusBar.simpleText := 'Creating document...';
    try
      screen.cursor := crHourglass;

      try
        MSWord := GetActiveOleObject('word.basic');
      except
        MSWord := createOleObject('word.basic');
      end;

      MSWord.fileNew(openDialog.FileName);
      MSWord.Insert('Line 1' + #13);
      MSWord.Insert('Line 2' + #13);
      MSWord.Insert('Line 3' + #13);
      MSWord.Insert('Line 4' + #13);
      MSWord.Insert('Line 5' + #13#13);
      MSWord.Insert(dateToStr(date) + #13#13);
      MSWord.Insert('Dear Sir/Madam,' + #13#13);

      MSWord.AppShow;
    finally
      screen.cursor := crDefault;
    end;
  end;
end;

There are two things I would like to do:

1) Set the filename so when they save the document, it makes a 
sensible suggestion. I do not want to actually save the document, as 
it will not always be saved. The FileName, and FullFileName strings 
are read only. 

I think I could use a macro that takes over the FileSave and 
FileSaveAs functions, but that means the code becomes reliant on the 
macro being in the template. If the user creates new templates, this 
may not be the case.

2) Change the window caption. I think this is the WindowName function.
This code works:

      showMessage(MSWord.windowName);

But I cannot see how to set it. I have tried all these plus some more:


      // MSWord.windowName := 'Test'; won't run
      // MSWord.windowName$ := 'Test'; Won't compile.
      // MSWord.[windowName$] := 'Test'; // Won't compile.
      // MSWord."windowName$" := 'Test'; // Won't compile.
      // MSWord.windowName('Test'); // Won't run.

The problem seems to be the $.

The other method is to use an OLEContainer, and edit in-place. This 
would give me more control. However, I cannot use the FileNew, 
FileSaveAs, and FilePrint methods. Therefore, I cannot create a 
document from a template, save it, nor print it. This seems to be a 
'feature' of in-place editing. correct?

I could use OLE Automation to create the document, save it, then 
create the OLEContainer object from the file. I cannot see a way to 
save any changes to a native Word document so I can load it in and 
print it. I can save it using the OLEContainers SaveToFile, but how do
I load it into Word using OLE Automation so I can print it? I.e., 
without the stuff the previous save has prepended.

This would mean:

1) Creating an OLE Automation pbject.
2) Creating the document from a template.
3) Making the changes.
4) Saving the document.
5) Closing the OLE Automation.
6) Loading the file into the OLE Container.
7) Letting the user make changes.
8) Saving the file.
9) Closing the OLE Container.
10) Creating an OLE Automation pbject.
11) Load the document.
12) Print the document.
13) Close the OLE Automation.

This seems to entail starting Word 3 times - steps 1, 6, and 10. Is 
there anyway to get an OLE Automation object directly into a 
TOLEContainer? Can I use CreateLinkFromFile so changes are reflected 
in both places?

TIA.


-----------------------------------------
Simon Thompson
Christchurch
New Zealand
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads