I have TWordApplication
named App
component on my form. It's ConnectKind
property is set to ckRunningOrNew
and AutoConnect
property is True
. When my procedure finishes, Word window appears on screen and after doing some tasks I close it. Next call to App
produces the topic error, even if I call Disconnect
.
procedure ReportButtonClick(Sender: TObject);
var
Doc: _Document;
{ Some other variables }
begin
App.Disconnect; // calling after closing produces error
App.Connect;
Doc := App.Documents.Add('path_to_template', EmptyParam, EmptyParam, EmptyParam);
{ Working with Doc }
App.Visible := True;
end;
It seems clear that I shouldn't close Word, but my clients consider keeping Word always opened is not convenient for them. I tried to catch the exception without success.
How should I handle this situation?