Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi and MS Word 2000

Posted on 2003-10-30
5
Medium Priority
?
752 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

705 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