Board index » delphi » OLE automation with Delphi 2.01 & Word 97

OLE automation with Delphi 2.01 & Word 97

Would someone know how to:

1- close Word upon finishing execution of a Delphi pgm which, at some
point, opened it using:
        ole := createOleObject('Word.application').
    I tried "ole.quit", which does not work, but does not cause an error
(what does it do?);
    I tried "old.close" too: same result...

2- how to detect that Word is running, and connect the OLE object with the
app that is already loaded in memory instead of starting a second instance?

Thanks

Michel Ranger
micr...@cam.org

 

Re:OLE automation with Delphi 2.01 & Word 97


This is one way, I'm sure there are others, to detect if word is running  

   temp := 'OpusApp';
       AHwnd :=  FindWindow(pchar(temp),nil);
       If (AHwnd = 0) then
           Begin
              Temp := WhereisWord + '\winword.exe /n';
              AnAnswer := WinExec(pchar(temp), 1);
              If (AnAnswer < 32) then
                 Begin
                    Warning('Ole Handler', 'Unable to find WinWord.exe');
                    Exit;
                 End;
           End;

This is a piece of {*word*99} to link into the currently running word,
steal the application object from it and then go on.  This makes
a document which you then have to trash (unless you really wanted
a new blank document based on the normal template).  

   try
         Basically := CreateOleObject('Word.Document.8');
       except
         Warning('Ole Handler', 'Could not start Microsoft Word.');
         Result := False;
         Exit;
       end;
    Try
         Wordy := Basically.Application;
       Except
           Begin
              Warning('Ole Handler', 'Could not access Microsoft Word.');
              Wordy := UnAssigned;
              Basically := UnAssigned;
              Exit;
           end;
       end;
   MyDocument := Wordy.ActiveDocument;
   MyDocument.close(wdDoNotSaveChanges);
   (* when you close this, you get either no documents open
      or the document the user was working on*)

To get your little hooks out of word
    automationobject := Unassigned;

Other Threads