Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Connect an OleContainer Word Document to a WordDocument Object

352 views
Skip to first unread message

H. Romero

unread,
Oct 11, 2002, 4:29:35 AM10/11/02
to
Hi

How could I connect a Word document created on a OleContainer with this
exppresion:

olecontainer1.createobject('Word.document',false);

To a WordDocument Object.

I always have to use an Olevariant object to do some of the capabilities of
the document, but the problem is when i try to create the doc with the
WordDocument object an then i try to view the document in the ole container.

Thanks in advance.
H. Romero


Deborah Pate (TeamB)

unread,
Oct 11, 2002, 11:55:26 AM10/11/02
to
<<James E Presley:
There seems to be no way to map the variant OLEObject to an
interface (in our case Word 2000) or even cast it so at
design time.
>>

Yes there is. The OleContainer's OleObject property holds
the document as an IDispatch, and you can just cast to the
interface you want. For example:

Doc: _Document;
..
OleContainer1.CreateObjectFromFile(Path, False);
OleContainer1.DoVerb(ovShow);
Doc := IDispatch(OleContainer1.OleObject) as _Document;

--
Deborah Pate (TeamB) http://delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html


Deborah Pate (TeamB)

unread,
Oct 11, 2002, 11:59:39 AM10/11/02
to
<<H. Romero:

How could I connect a Word document created on a
OleContainer with this exppresion:

olecontainer1.createobject('Word.document',false);

To a WordDocument Object.
>>

If you mean to a TWordDocument component:
WordDocument1.ConnectTo(
IDispatch(OleContainer1.OleObject) as _Document);

However it's probably not a good idea to have two
components fighting for ownership of a single document. You
can use an interface variable, as shown in my answer to
James, to get the benefits of early binding with less
overhead than the TWordDocument component.

James E Presley

unread,
Oct 11, 2002, 2:13:15 PM10/11/02
to
Deborah - I salute you. Works like a charm...yahoo! I'm so glad I replied to
John!

"Deborah Pate (TeamB)" <d.p...@blueyonder.co.not-this-bit.uk> wrote in
message news:VA.0000178...@blueyonder.co.not-this-bit.uk...
> <<James E Presley:


0 new messages