BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Load MSWord from a memory file

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Marin Atanasov
Guest





PostPosted: Fri Jun 27, 2003 11:12 am    Post subject: Re: Load MSWord from a memory file Reply with quote



Hi, George!
Hope, I'm not too late with the answer.

Yes, MSWord cannot load it's document from any place, but the file.
But!
I solved problem, getting different point of view on it.
I needed to Hold documents in a database, but their sources(originals) are
word files.
So I read them and put in the database, so I can read them back later.

Here you are some code illustrating my words, because my English is too bad
:

Assume that:
"OLE1" is an OLEContainer.

===== 1 ====== Opening DOC file and saving it into database :

procedure TfrmMain.DocFileImport(aFileName: String; Qry: TQuery);
var
BlobMemStream:TMemoryStream;
......
begin
OLE1.CreateObjectFromFile(aFileName,false);
OLE1.Close;
BlobMemStream:=TMemoryStream.Create;
OLE1.SaveToStream(BlobMemStream);
BlobMemStream.Seek( 0, soFromBeginning);

With uQry do
begin
Close;
SQL.Text := 'INSERT INTO MyTable VALUES ( :docBody)';
ParamByName(aParamName).LoadFromStream(aStream, ftBlob);
ExecSQL;
FreeAndNil(BlobMemStream);
end;
end;

===== 2 ====== Loading DOC from database in OLEContainer :
Procedure LoadDatabaseDoc( Qry : TQuery);
Var
MemBlobStream : TStream;
begin
With Qry do
begin
Close;
SQL.Text := 'SELECT docBody FROM MyTable';
Open;
try
try

MemBlobStream:=Qry.CreateBlobStream(Qry1.FieldByName('advTemplateBody'),bmRe
ad);
MemBlobStream.Seek( 0, soFromBeginning);
OLE1.LoadFromStream( MemBlobStream);
finally
FreeAndNil( MemBlobStream);
end;
finally
Close;
end;
end;

In other words, you save OLEContainer's content to stream which is OLE
Header + OLE Document, which gives you ability to load it later. Word as an
application cannot load document from stream, but OLEContainer can read any
ole object data and construct ole object depending on data. (of course OLE
Server must present in order to edit document e.g. you must have Word
installed on the computer which need to run your program if program requires
document editing).

Hope, it will help you,
Marin


"GW" <george.wnag (AT) justice (DOT) com> wrote

Quote:
In Delphi 7pro, I need to open and view a Word document in MSWord from
memory (binary stream-retrieved from database). In the past, for lacking a
better way of doing it, I just saved the stream to a temp file and then
ask
MSWord to open the temp file. I think there must be a way of sending the
stream directly from memory to Word, sort of a loadFromStream method. Can
anyone help? Thanks.

--George






Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.