Solved

Delphi and MS Word 2000

Posted on 2003-10-30
5
724 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
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now