 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Quin Guest
|
Posted: Thu Jan 22, 2004 12:11 pm Post subject: Word docs in BLOB |
|
|
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
|
Posted: Thu Jan 22, 2004 8:54 pm Post subject: Re: Word docs in BLOB |
|
|
*************************
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
|
Posted: Thu Jan 22, 2004 11:29 pm Post subject: Re: Word docs in BLOB |
|
|
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
|
Posted: Fri Jan 23, 2004 5:40 am Post subject: Re: Word docs in BLOB |
|
|
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
|
Posted: Sat Jan 24, 2004 1:24 am Post subject: Re: Word docs in BLOB |
|
|
| 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 |
|
 |
|
|
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
|
|