将olecontainer中的word文档保存到数据库的bolb字段,如何显示问档内容,先谢了!(100分)

Y

ytwin

Unregistered / Unconfirmed
GUEST, unregistred user!
各位delphi高手,我先谢谢大家了。我这里有一个问题:
我将olecontainer中的文档存入到数据库的blob字段中,用Grid显示table的blob字段中
只有‘BLOB’我showmessage 测了一下,size不为零,表明存进去了,但我看不到文档的内容
请教各位高手如何在blob字段中看到文档的内容,万分感谢!
 
这不可能
 
bbcoll:
你好,为什么做不到?
有什么方法可以达到类似的目的呢?请告知。
 
bbcoll:
那我如何可以不让表中的blob字段中显示'BLOB',而改为‘略’呢?望告之。
 
var
Stream1:TBlobStream;
// Stream2:TMemoryStream;
begin
Stream1:= TBlobStream.Create(Table1Notes, bmRead);
OleContainer1.LoadFromStream(Stream1);
end;

 
Stream1.free
 
又用olecontainer来显示blob字段的内容
 
arm:
你好,我好象说的是在表中的blob字段如何不显示'BLOB'或显示‘略’,在olecontainer中
显示我做出来了,还得麻烦你了。
 
ytwin:
你好,我好象说的是在表中的blob字段如何不显示'BLOB'或显示‘略’,在olecontainer中
显示我做出来了,还得麻烦你了。
请问您是怎样做的,能否把原代码告知,在这里先谢过了。我有一段代码,但总是出错,
procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
var
BS:TBlobStream;
begin
bs:=TBlobStream.Create(Table1.FieldbyName('neirong') as TBlobField,bmRead);
if BS.Size<>0 then
try
with olecontainer1 do
begin
LoadFromStream(BS); //////在这里提示“invalid Stream format“错误
if State<>osEmpty then
Iconic:=true;
end;
finally
bs.Free;
end;
end;
在LoadFromStream处总是出现“invalid stream format”错误?
我实在想不出什么解决办法?

另外这条语句也出现这个错误:
olecontainer1.LoadFromFile('C:/lsz/guangpan/zhijiaguicheng/94/qqq.doc');
 
我知道我的不正确

但是,如果你去掉bs.free,他就没有错误了

我原来也是这样,找了好长时间的错误,结果去掉free句可以

我也不知道为什么?
 
如下:

打开文件:
olecontainer1.CreateObjectFromFile('C:/lsz/guangpan/zhijiaguicheng/94/qqq.doc',false);

保存到数据库:
var
Stream1:TBlobStream;
begin
olecontainer1.CreateObjectFromFile('C:/lsz/guangpan/zhijiaguicheng/94/qqq.doc',false);
Stream1:= TBlobStream.Create(Table1Notes, bmwrite);
OleContainer1。SavetoStream(Stream1);
Table1.post;
end;

从数据库加载:
var
Stream1:TBlobStream;
begin
Stream1:= TBlobStream.Create(Table1Notes, bmRead);
OleContainer1.LoadFromStream(Stream1);
OleContainer1.run;
end;

注意:只有用OleContainer1。SavetoStream(Stream1);的数据流才能用
OleContainer1.LoadFromStream(Stream1); 打开,其他的比如用 TfileStream
保存进数据库的是不能直接打开的。





 
我用了parable的代码试了,怎么会出现'stream read error' 好像无法从数据库中加载!
 
哦,这个可能是流格式不一样。
你把OleContainer1的 流格式改成旧格式试试。
另外,可以用BlobField.SaveToStream试试
 
你可以用Woll2woll 的inforpower200的控件,问题都可以解决!
 
emailcdz:
how to do that by using IP?
 
没有整理,希望有帮助!:)

procedure PfbtOKPaperImport();
var
vTestType,vTestDiff:String;
vItemIndex:integer;
strContent,strAnswer:Tmemorystream;
begin
if MainForm.fnedContentImport.text='' then
begin
Application.messageBox('试卷输出文档名没有填写!','错误',mb_ok+MB_ICONWARNING);
MainForm.fnedContentImport.SetFocus;
exit;
end;
if MainForm.fnedAnswerImport.Text='' then
begin
Application.messageBox('答卷输出文档名没有填写!','错误',mb_ok+MB_ICONWARNING);
MainForm.fnedAnswerImport.SetFocus;
exit;
end;


// 添加试卷及答案记录
dm.tbExamInformation.Open;
dm.tbExamInformation.Append;
dm.tbExamInformation.FieldByName('TestYear').AsString:=MainForm.seTestYear.Text;
dm.tbExamInformation.FieldByName('TestTerm').AsString:=MainForm.fcbTestTerm.Text;
dm.tbExamInformation.FieldByName('TestSpeciality').AsString:=MainForm.dblcSpecialityName.Text;
dm.tbExamInformation.FieldByName('TestType').AsString:=vTestType;
dm.tbExamInformation.FieldByName('TestDifficulty').AsString:=vTestDiff;

strContent:=Tmemorystream.Create; // 处理试卷
strContent.LoadFromFile(MainForm.fnedContentImport.Text);
strContent.Position:=0;
Tblobfield(dm.tbExamInformation.FieldByName('TestContent')).loadfromstream(strContent);

strAnswer:=Tmemorystream.Create; // 处理答卷
strAnswer.LoadFromFile(MainForm.fnedAnswerImport.Text);
strAnswer.Position:=0;
Tblobfield(dm.tbExamInformation.FieldByName('TestAnswer')).loadfromstream(strAnswer);

try
dm.tbExamInformation.Post;
finally
begin
strContent.Free;
strAnswer.Free;
end
end;

dm.tbExamInformation.Close;

ShowMessage('试卷及答卷导入成功!');
end;

procedure fbtExitPaperImport();
begin
ExitToBegin();
end;

procedure fbtOKPaperExport();
var
str:Tmemorystream;
begin
if MainForm.fnedContentExport.text='' then
begin
Application.messageBox('试卷输出文档名没有填写!','错误',mb_ok+MB_ICONWARNING);
MainForm.fnedContentExport.SetFocus;
exit;
end;
if MainForm.fnedAnswerExport.Text='' then
begin
Application.messageBox('答卷输出文档名没有填写!','错误',mb_ok+MB_ICONWARNING);
MainForm.fnedAnswerExport.SetFocus;
exit;
end;

str:=Tmemorystream.Create;
str.Position:=0;
Tblobfield(dm.tbExamInformation.FieldByName('TestContent')).savetostream(str);
str.SaveToFile(MainForm.fnedContentExport.Text);
str.Free;

str:=Tmemorystream.Create;
str.Position:=0;
Tblobfield(dm.tbExamInformation.FieldByName('TestAnswer')).savetostream(str);
str.SaveToFile(MainForm.fnedAnswerExport.Text);
str.Free;

ShowMessage('试卷及答卷导出成功!');
end;
 
为什么我的delphi6中不支持tblobstream?提示该类不存在!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
956
SUNSTONE的Delphi笔记
S
S
回复
0
查看
779
SUNSTONE的Delphi笔记
S
顶部