Solved

Delphi and MS Word 2000

Posted on 2003-10-30
5
738 Views
Last Modified: 2011-08-18
Hello,

I am working on a Delphi program that creates word document and writes to the document. I am using Delphi 5.0 and MS Word 2000 programs. I am able to create a blank document but not able to write anything to it .... Everytime I do, I get access violation.


PLEASEEEEEEEEEEEEE HELP

Sample code or actual code that I can use and practice on that writes to the document would be a great help thanks.
0
Comment
Question by:Digitalanolog1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 500 total points
ID: 9656352
Hi,

Try this:

uses ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
  WordApp, WordDoc: OLEVariant;
begin
 WordApp := CreateOleObject('Word.Application');
 WordApp.Visible := True; // show MS Word
 WordApp.Caption:='Winword From Delphi';
 // to open an existing doc
 // WordDoc:=WordApp.Documents.Open('Letter.dot');
 // to create new doc
 WordDoc:=WordApp.Documents.Add;
 WordDoc.Paragraphs.Item(1).Range.Bold :=True;
 WordDoc.Paragraphs.Item(1).Range.Font.Size :=30;
 WordDoc.Paragraphs.Item(1).Range.Font.Name:='Tahoma';
 WordDoc.Paragraphs.Item(1).Range.Text:= 'Welcome To Delphi World';
 // save the doc
 WordDoc.SaveAs('c:\mydoc.doc');
 // print the doc
 // WordDoc.PrintOut;
 WordDoc.Close; // closes the current document
 WordApp.Quit; // exits MS Word
end;

Regards, Geo
0
 
LVL 5

Expert Comment

by:DeerBear
ID: 9659685
Hi,

To do what you want, I would use Server components in the
Delphi palette( yes, there's the updated version for D5 too ).

I would only use them for testing, though, since if you use them in
production code your app will be bound to that specific Word version.

HTH,

Andrew
0
 

Author Comment

by:Digitalanolog1
ID: 9662801
Hi Geo,

does your sample code work with any version of MS word program? Oh by the way your code works.

:) thanks man

0
 
LVL 17

Expert Comment

by:geobul
ID: 9669462
Hi,

It works with MS Word 97 and 2000. It should work with XP also but I haven't tried that yet.

Regards, Geo
0
 

Expert Comment

by:alvictor
ID: 10012364
Hello guys.

I am working with Delphi and Word just like you seem to work. But the difference is that I'm not working with desktop application, but ActiveX Components embed into web pages.

Until now I was able to use the TOleContainer just fine, I can let the user edit and modify the document. But when I need to automate the changes, using the TWordApplication component (coding just like as coding for desktop applications), it just doesn't work. I've tried several differents implementations, but every one of them give me an unespecified error message.

Do you know if there are some limitations of using ActiveX Components such as these into web pages???

Thanks a lot.
- Al Victor.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question