word文件传入和传出数据库
uses IdGlobal;
procedure TdjhyForm.SpeedButton2Click(Sender: TObject);
var
sfilename:string;
function BlobContentTostring(const Filename:string):string;
begin
with Tfilestream.Create(filename,fmopenread) do
try
setlength(result,size);
read(pointer(result)^,size);
finally
free;
end;
end;
begin
if opendialog1.Execute then
begin
sfilename:=opendialog1.FileName;
DataModule1.ADOQuery14.Edit;
DataModule1.ADOQuery14.FieldByName('word').AsString:=blobcontenttostring(sfilename);
DataModule1.ADOQuery14.Post;
end;
end;
procedure TdjhyForm.SpeedButton1Click(Sender: TObject);
var
sfilename:string;
bs:Tadoblobstream;
begin
bs:=Tadoblobstream.Create(TBLOBfield(DataModule1.ADOQuery14.FieldByName('word')),bmread);
try
sfilename:=extractfilepath(application.ExeName)+trim(DataModule1.adoquery14.fieldbyname('hybh').AsString);
sfilename:=sfilename+'.'+'doc';
bs.SaveToFile(sfilename);
try
djhyopenform:=Tdjhyopenform.Create(self);
djhyopenform.olecontainer1.CreateObjectFromFile(sfilename,false);
djhyopenform.OleContainer1.Iconic:=true;
djhyopenform.ShowModal;
finally
djhyopenform.Free;
end;
finally
bs.free;
end;
end;
procedure TdjhyForm.SpeedButton2Click(Sender: TObject);
var
sfilename:string;
function BlobContentTostring(const Filename:string):string;
begin
with Tfilestream.Create(filename,fmopenread) do
try
setlength(result,size);
read(pointer(result)^,size);
finally
free;
end;
end;
begin
if opendialog1.Execute then
begin
sfilename:=opendialog1.FileName;
DataModule1.ADOQuery14.Edit;
DataModule1.ADOQuery14.FieldByName('word').AsString:=blobcontenttostring(sfilename);
DataModule1.ADOQuery14.Post;
end;
end;
procedure TdjhyForm.SpeedButton1Click(Sender: TObject);
var
sfilename:string;
bs:Tadoblobstream;
begin
bs:=Tadoblobstream.Create(TBLOBfield(DataModule1.ADOQuery14.FieldByName('word')),bmread);
try
sfilename:=extractfilepath(application.ExeName)+trim(DataModule1.adoquery14.fieldbyname('hybh').AsString);
sfilename:=sfilename+'.'+'doc';
bs.SaveToFile(sfilename);
try
djhyopenform:=Tdjhyopenform.Create(self);
djhyopenform.olecontainer1.CreateObjectFromFile(sfilename,false);
djhyopenform.OleContainer1.Iconic:=true;
djhyopenform.ShowModal;
finally
djhyopenform.Free;
end;
finally
bs.free;
end;
end;