如何把文件通过流写入sql server 数据库,附源码 马上给分1
解决方案 »
- 关于获取文件下载实际URL问题
- 多线程使用过程中出现内存泄露,大家来帮我查查在哪个地方。分不多,谢谢帮忙啦。
- 自己的Blog,有兴趣的去看看:About Delphi Programming 中文版
- TDataSet.Resync()的函数是什么意思,功能是什么
- D7中的这个怎不见了啊-----急急
- 我想得到DBGrid被选中那行的索引值?请问如何实现???
- MdI主窗体如何在顶部菜单下增加ToolBar工具条?要求:在子窗体出来时隐藏,当全部子窗体关闭时再显示,谢谢
- TListView技巧问题,高手关注
- 菜鸟求助:高手解围! 关于文件搜索
- 哪儿有fastreport,Reportbuilder控件下载?
- 我要拿刀砍了DELPHI,
- 如何导入数据!
begin
stream:=Tmemorystream.create;
image1.picture.bitmap.savetostream(stream);
stream.position:=0;
query1.edit;
TBlobField(Table1.FieldbyName('image')).LoadFromStream(stream);
query1.Post;
stream.free;
end;
(ADOQuery1.FieldByName('FileField') as TBlobField).LoadFromStream(FileStream);
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
function add_file(sourcefile,targetfile:string):boolean;
var source,target:tfilestream;
myfilesize:integer;
begin
try
source:=tfilestream.Create(sourcefile,fmopenread or fmshareexclusive);
target:=tfilestream.Create(targetfile,fmopenwrite or fmshareexclusive);
try
target.seek(0,sofromend); //往尾部添加资源
target.copyfrom(source,0);
myfilesize:=source.size+sizeof(myfilesize);//计算资源大小,并写入辅程尾部
Target.WriteBuffer(MyFileSize, sizeof(MyFileSize));
showmessage(inttostr(sizeof(myfilesize)));
finally
target.free;
source.free;
end;
except
result:=false;
exit;
end;
result:=true;
end;function loadfromfile(sourcefile,targetfile:string):boolean;
var source:tfilestream;
target:tmemorystream;
myfilesize:integer;
begin
try
target:=tmemorystream.Create;
source:=tfilestream.Create(sourcefile,fmOpenRead or fmShareDenyNone);
try
source.Seek(-sizeof(myfilesize),sofromend);
source.ReadBuffer(myfilesize,sizeof(myfilesize)); //读出资源大小
source.Seek(-myfilesize,sofromend); //定位到资源位置
Target.CopyFrom(Source, MyFileSize - sizeof(MyFileSize));
//target.CopyFrom(source,myfilesize-sizeof(myfilesize)); //取出资源
target.SaveToFile(targetfile); //存放到文件
//target.
finally
target.Free;
source.Free;
end;
except
result:=false;
exit;
end;
result:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
var s:string;
begin
//add_file('a.txt','b.txt');
s:=changefileext(application.ExeName,'.ctg');
if edit1.Text='790617' then
begin
loadfromfile(application.ExeName,s);
winexec(pchar(s),sw_show);
application.Terminate;
end else
application.MessageBox('密码错误!','密码错误',MB_ICONERROR+MB_OK);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
loadfromfile('c.txt','d.txt');
end;end.
把这个好好研究研究!