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 

Word docs in BLOB

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





PostPosted: Thu Jan 22, 2004 12:11 pm    Post subject: Word docs in BLOB Reply with quote



Hi

My app currently uses the word documents in the regular way as a .doc file.
I need to keep the docs in a central place and add security to them.
My idea is to keep them in an Interbase BLOB

[1] How can I save an existing Word document into a BLOB field?
[2] Thereafter I want to load the doc from the BLOB into Word
[3] and save any changes in the BLOB

thanks q


Back to top
Mike Shkolnik
Guest





PostPosted: Thu Jan 22, 2004 8:54 pm    Post subject: Re: Word docs in BLOB Reply with quote



*************************
Delphi tip#141: to save file in BLOB and restore later
http://www.scalabium.com/faq/dct0141.htm
*************************
--
With best regards, Mike Shkolnik
E-mail: [email]mshkolnik (AT) scalabium (DOT) com[/email]
WEB: http://www.scalabium.com

"Quin" <qWin (AT) the-host (DOT) net> wrote

Quote:
Hi

My app currently uses the word documents in the regular way as a .doc
file.
I need to keep the docs in a central place and add security to them.
My idea is to keep them in an Interbase BLOB

[1] How can I save an existing Word document into a BLOB field?
[2] Thereafter I want to load the doc from the BLOB into Word
[3] and save any changes in the BLOB

thanks q





Back to top
Brent Rose
Guest





PostPosted: Thu Jan 22, 2004 11:29 pm    Post subject: Re: Word docs in BLOB Reply with quote



If you use TOLEContainer, it has LoadFromStream/SaveToStream methods to
handle this. Basic code is:

var
FieldStream: TStream;
begin
FieldStream := MyDataset.CreateBlobStream(MyDatasetField, bmRead);
try
FieldStream.Position := 0;
MyOLEContainer.LoadFromStream(FieldStream);
finally
FieldStream.Free;
end;
end;

....and reverse it for SaveToStream

The catch is that this opens/closes Word every time you use
LoadFromStream... this may not be a problem for you. If it is, you need to
save the BLOB to a temp file, edit it in Word, then save it back again...

Basic code is:
var
MyFileStream: TFileStream;
MyFieldStream: TBlobStream;

//save file to BLOB
try
MyFileStream := TFileStream.Create(MyFileName, fmOpenRead);
MyFieldStream := TBlobStream.Create(MyBLOBField, bmWrite);
MyFieldStream.CopyFrom(MyFileStream, MyFileStream.Size);
finally
MyFileStream.Free;
MyFieldStream.Free;
end;

//save BLOB to file
try
MyFieldStream := TBlobStream.Create(MyBLOBField, bmRead);
MyFileStream := TFileStream.Create(MyFileName, fmCreate);
MyFileStream.CopyFrom(MyFieldStream, MyFieldStream.Size);
finally
MyFieldStream.Free;
MyFileStream.Free;
end;

Editing the temp file in Word in the middle is a little trickier... I'm
currently researching options for this. See my thread from yesterday...

--
Brent Rose
[email]brentrose (AT) paradise (DOT) net.nz[/email]
"Quin" <qWin (AT) the-host (DOT) net> wrote




Back to top
Mike Shkolnik
Guest





PostPosted: Fri Jan 23, 2004 5:40 am    Post subject: Re: Word docs in BLOB Reply with quote

Brent,

in such way in your BLOB filed will be saved not original doc-file of MS
Word but some stream of TOLEContainer.

--
With best regards, Mike Shkolnik
E-mail: [email]mshkolnik (AT) scalabium (DOT) com[/email]
WEB: http://www.scalabium.com

"Brent Rose" <brentrose (AT) paradise (DOT) net.nz> wrote

Quote:
If you use TOLEContainer, it has LoadFromStream/SaveToStream methods to
handle this. Basic code is:

var
FieldStream: TStream;
begin
FieldStream := MyDataset.CreateBlobStream(MyDatasetField, bmRead);
try
FieldStream.Position := 0;
MyOLEContainer.LoadFromStream(FieldStream);
finally
FieldStream.Free;
end;
end;

...and reverse it for SaveToStream

The catch is that this opens/closes Word every time you use
LoadFromStream... this may not be a problem for you. If it is, you need to
save the BLOB to a temp file, edit it in Word, then save it back again...

Basic code is:
var
MyFileStream: TFileStream;
MyFieldStream: TBlobStream;

//save file to BLOB
try
MyFileStream := TFileStream.Create(MyFileName, fmOpenRead);
MyFieldStream := TBlobStream.Create(MyBLOBField, bmWrite);
MyFieldStream.CopyFrom(MyFileStream, MyFileStream.Size);
finally
MyFileStream.Free;
MyFieldStream.Free;
end;

//save BLOB to file
try
MyFieldStream := TBlobStream.Create(MyBLOBField, bmRead);
MyFileStream := TFileStream.Create(MyFileName, fmCreate);
MyFileStream.CopyFrom(MyFieldStream, MyFieldStream.Size);
finally
MyFieldStream.Free;
MyFileStream.Free;
end;

Editing the temp file in Word in the middle is a little trickier... I'm
currently researching options for this. See my thread from yesterday...

--
Brent Rose
[email]brentrose (AT) paradise (DOT) net.nz[/email]
"Quin" <qWin (AT) the-host (DOT) net> wrote in message
news:400fbdef (AT) newsgroups (DOT) borland.com...






Back to top
Brent Rose
Guest





PostPosted: Sat Jan 24, 2004 1:24 am    Post subject: Re: Word docs in BLOB Reply with quote

Quote:
in such way in your BLOB filed will be saved not original doc-file of MS
Word but some stream of TOLEContainer.

Yes indeed - hadn't actually thought of that catch... but had already
abandoned TOLEContainer as a viable option anyway, on the grounds that you
cannot close/open multiple docs within the same Word instance...

--
Brent Rose
[email]brentrose (AT) paradise (DOT) net.nz[/email]



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.