Board index » delphi » Run away from Word 97 OLE Automation

Run away from Word 97 OLE Automation

You'll create some prototype code using Late Binding, and then find
Borders.Add() can't be translated into Early Binding and that
BorderStyle simply crashes Word.
You'll find your preliminary test runs quickly but drags to a snail's
pace after half a page or manipulating tables.
You'll hit crashes in all sorts of unexpected places, such as crossing a
page in a table.
You'll find your code messes up, when the cursor mysteriously jumps out
of the header, simply by accessing page info.
You'll try to write local macros to improve performance but find you
can't pass parameters to them.
You'll want to insert formatted, RTF text but find it can only be done
via the global clipboard.
You'll allow the user to select a printer but then find you can't tell
Word what printer to use, unless you change the system-wide default.
You'll finally give up fighting this never ending source of bugs,
wasting months of work.

Avoid Word 97 OLE Automation, while you still have some hope!

Matthew Greet - a veteran of fighting Word 97 OLE Automation and RTF
v1.5

mgr...@warmachine.u-net.com

--
Windows 98 - still not 32 bit.

Sent via Deja.com http://www.deja.com/
Before you buy.

 

Re:Run away from Word 97 OLE Automation


I share your frustration. However it is possible to get round many of your
problems.

Quote
> You'll create some prototype code using Late Binding, and then find
> Borders.Add() can't be translated into Early Binding and that
> BorderStyle simply crashes Word.

MS actually suggest we use late binding as it means you are not calling a
specific type library and I guess means that they can{*word*222}us eventually by
removing Word97 compatibility (my Word97 classes apparently work with
Word2000 without change so I presume Word2000 has both type libraries -
anyone know?).
I prefer early binding for many reasons (see my web site). However, as you
have discovered, the type library is a little "unfinished" and you
occasionally have to resort to late binding. Simply typecast the object as
OleVariant and you can work with it as you would late binding. This can be
useful where you want a quick and dirty way to print as you can forget
optional parameters.
I haven't used Borderstyle but paragraph styles don't like being refered to
as strings - try variants and use Word constants where possible.

Quote
> You'll find your preliminary test runs quickly but drags to a snail's
> pace after half a page or manipulating tables.

Tables are faster if you make them in a Word macro (see my demos). The
fastest way of inserting a table that I have found (short of creating a rtf
file and reading it in) is to send a big chunk of comma/tab delimited data
and then use the text to table methods. This works almost instantly and you
can apply styles while you are at it (again, I have a demo).

Quote
> You'll hit crashes in all sorts of unexpected places, such as crossing a
> page in a table.

Word is rather buggy

Quote
> You'll find your code messes up, when the cursor mysteriously jumps out
> of the header, simply by accessing page info.

Try to use ranges. They are faster as you don't get any cursor/selection
action on screen and they are immune to where the cursor is. It is easy to
convert between ranges and the selection object but be aware that they have
slightly different syntax for their move/inserting/sizing methods. If you
must use selections, turn of screen updating while manipulating the text.

Quote
> You'll try to write local macros to improve performance but find you
> can't pass parameters to them.

You can do this by using custom Word properties (again, I have an example).

Quote
> You'll want to insert formatted, RTF text but find it can only be done
> via the global clipboard.

I think Joe Milne knows a bit about transferring data between Word & Delphi
(don't know whether this is two-way though). See
http://www.softmosis.ca/WordFAQ.html

Quote
> You'll allow the user to select a printer but then find you can't tell
> Word what printer to use, unless you change the system-wide default.

Haven't looked into this but I will.

Quote
> You'll finally give up fighting this never ending source of bugs,
> wasting months of work.

Almost. I have found sharing my experiences (good and bad) has got me
through the difficult spots. This newsgroup can be therapy!

Quote
> Avoid Word 97 OLE Automation, while you still have some hope!

If you can do what you need to do without Word, I would definitely do it
that way. While the reporting newsgroup is filled with report generator
woes, the custom Delphi solutions are usually less painful that Word.

BTW - if you have discovered any neat tricks while programming Word, I'd
love to hear from you.

Regards

Dr Allan Harkness
See my Word classes at
http://www.atheroma.freeserve.co.uk/

Other Threads