Using WordApplication in Delphi 2010 [Edit]

Hello Everyone,

  I am having a problem with WordApplicatio component. I am using Delphi 10.

  I can get the WordApplication to open with the Document template that I select, but Word is behind my app and when I close

  Word I get an RPC Server not available errror and after that a pointer violation and then access violations until I reset the IDE.

  Here is the code I am using:

  procedure TTestLetterForm.Button1Click(Sender: TObject);
var
  FileName: oleVariant;
begin
  //Letter2Report.Print;

  if OpenDialog.Execute = True then
   begin
     FileName := OpenDialog.FileName;

      WordApplication1.Documents.Open(FileName,EmptyParam,
        EmptyParam,EmptyParam,EmptyParam,
        EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
        EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);

      WordApplication1.Visible := True;

   end;
end;

How do I stop the errors and how do I get data to the word document which is a letter with multiple fields.

Any help with this will be very appreciated as I am under the gun to get this app working.

Thanks and have a great day!

Keith Hancock

Edited by: Keith Hancock on Oct 10, 2011 8:13 AM

Edited by: Keith Hancock on Oct 11, 2011 6:35 AM
0
Keith
10/11/2011 1:36:47 PM
embarcadero.delphi.ole 598 articles. 1 followers. Follow

1 Replies
1951 Views

Similar Articles

[PageSpeed] 10
Get it on Google Play
Get it on Apple App Store

> {quote:title=Keith Hancock wrote:}{quote}
> Hello Everyone,
> 
>   I am having a problem with WordApplicatio component. I am using Delphi 10.
> 
>   I can get the WordApplication to open with the Document template that I select, but Word is behind my app and when I close
> 
>   Word I get an RPC Server not available errror and after that a pointer violation and then access violations until I reset the IDE.
> 
>   Here is the code I am using:
> 
>   procedure TTestLetterForm.Button1Click(Sender: TObject);
> var
>   FileName: oleVariant;
> begin
>   //Letter2Report.Print;
> 
>   if OpenDialog.Execute = True then
>    begin
>      FileName := OpenDialog.FileName;
> 
>       WordApplication1.Documents.Open(FileName,EmptyParam,
>         EmptyParam,EmptyParam,EmptyParam,
>         EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
>         EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
> 
>       WordApplication1.Visible := True;
> 
>    end;
> end;
> 
> How do I stop the errors and how do I get data to the word document which is a letter with multiple fields.
> 
> Any help with this will be very appreciated as I am under the gun to get this app working.
> 
> Thanks and have a great day!
> 
> Keith Hancock
> 
> Edited by: Keith Hancock on Oct 10, 2011 8:13 AM
> 
> Edited by: Keith Hancock on Oct 11, 2011 6:35 AM

Hello

As I can see there is some sort of misunderstanding.

When you are using WordApplication component you launch instance of MS Word at the same moment.

And if you try to close MS Word before your program hasn't done all operations you will get errors listed above.

So you can launch MS Word in tray if you set 
              WordApplication1.Visible := False;

If you are using old format of office documents then you have no other choice but to run instance of MS Word at the same time
and edit your document with WordApplication methods.

If you are using new format then try using OpenXML based code. Then you won't have to launch MS Word and still could make all operations.

Good luck!
0
Alexander
10/30/2011 10:16:20 PM
Reply:

Web resources about - Using WordApplication in Delphi 2010 [Edit] - embarcadero.delphi.ole

CodeSOD: Breaking Delphi
... Break = interface ( IDispatch ) ['{79635BF1-BD1D-4B3F-A520-C1106F1AAAD8}'] function Get_Application : WordApplication ; safecall ; function ...

Resources last updated: 12/26/2015 11:27:00 AM