Board index » delphi » Word in a Form

Word in a Form


2006-11-27 05:09:42 PM
delphi71
G'day all
D7 Pro, Word 2000
Can I get Word to appear within a Delphi form? I have tried
using a Delphi MDI form and starting Word, but Word still appears
just in its own normal window, quite separate to my app.
I want to use Word to generate reports, but I don't want the user
to be able to save the report as a Word doc. On my Delphi form I
want to have a Save button that saves Word's text (via RTF)
directly to my MS SQL Server 7 database.
Any help gratefully appreciated, especially with lnes of code.
Cheers
Bill
 
 

Re:Word in a Form

You could use a TOLEContainer.
Brian
 

Re:Word in a Form

<<Bill C:
On my Delphi form I want to have a Save button that saves
Word's text (via RTF) directly to my MS SQL Server 7
database.
Quote
>
The TOleContainer component will let you have Word in a form
and save to (and load from) a stream, and hence to a database
blobfield. It doesn't save in RTF format, however. If you
must have that you will have to use an intermediate file.
--
Deborah Pate (TeamB) delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html
 

Re:Word in a Form

Thanks for both responses. This seems to be a way to go. I haven't used olecontainers before, so I have got a bit of learning to do.
I have been playing with the Delphi 7 Pro demo named olesdi to get a feel for the approach.
One problem that has arisen is that whilst a Word doc file (created with Word 2000) loads fine into the olecontainer and I can edit it with the doubleclick, when I save it just using the standard olesdi app (from within the IDE), the saved doc file is trashed and now, when I re-open the file in Word itself, it shows just garbage around the original text, like...
BDOCv ????, etc.
Any suggestions as to why this occurs?
Thanks again
Bill
"Deborah Pate (TeamB)" <XXXX@XXXXX.COM>writes:
Quote
<<Bill C:
On my Delphi form I want to have a Save button that saves
Word's text (via RTF) directly to my MS SQL Server 7
database.
>>

The TOleContainer component will let you have Word in a form
and save to (and load from) a stream, and hence to a database
blobfield. It doesn't save in RTF format, however. If you
must have that you will have to use an intermediate file.

--
Deborah Pate (TeamB) delphi-jedi.org

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


 

Re:Word in a Form

<<Bill C:
the saved doc file is trashed and now, when I re-open the
file in Word itself, it shows just garbage
Quote
>
TOleContainers save in their own format unless you use their
SaveAsDocument methods. Unfortunately there is no
SaveAsDocumentToStream method, so if anything other than your
olecontainer is going to load the document from your
database, you will need to save to an intermediate file.
--
Deborah Pate (TeamB) delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html
 

Re:Word in a Form

Thanks for your reply, Deb
I haven't tried to use text from my database yet. All I did was to open and save a Word 2000 doc file using the code in the
olesdi demo app provided with D7. To open a doc file, the demo code is...
with OpenDialog1 do
if Execute then
begin
OleContainer1.CreateObjectFromFile(FileName, False);
ObjectFileName := FileName;
// set some buttons...
end;
This drops the doc into the olecontainer.
I double clicked the olecontainer to activate Word, and used the
File | Save menu item. The code in the olesdi demo is
simply...
OleContainer1.SaveToFile(FileName);
This reduces the original good doc file to garbage as described
earlier with lots of page and column breaks
Any suggestions?
Cheers
Bill
"Deborah Pate (TeamB)" <XXXX@XXXXX.COM>writes:
Quote
<<Bill C:
the saved doc file is trashed and now, when I re-open the
file in Word itself, it shows just garbage
>>

TOleContainers save in their own format unless you use their
SaveAsDocument methods. Unfortunately there is no
SaveAsDocumentToStream method, so if anything other than your
olecontainer is going to load the document from your
database, you will need to save to an intermediate file.

--
Deborah Pate (TeamB) delphi-jedi.org

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