我把程序放进服务器的数据库中,客户端在登陆时自动从数据库中更新最新版本。
还有,我把exe文件的扩展名改成其他比如ttt,怎么在程序中打开这样的文件 *.ttt
10 个解决方案
#1
二进制
#2
就当成一个文件来存放吧
#3
哪位GG给段代码啊
#4
procedure TForm1.Button1Click(Sender: TObject);
begin
AdoQuery1.SQL.Add('insert into test(bf) values(:p)');
Adoquery1.Parameters.ParamByName('p').LoadFromFile('c:\test.doc',ftBlob);
AdoQuery1.ExecSQL;
end;
procedure TForm1.Button2Click(Sender: TObject);
var MS: TMemoryStream;
begin
AdoQuery1.Close;
AdoQuery1.SQL.Add('select * from test');
AdoQuery1.Open;
Ms:=TMemoryStream.Create;
TBlobField(AdoQuery1.FieldByName('bf')).SaveToFile('c:\outtest.doc');
end;
access数据库用ole字段,sql数据库可以用image字段
begin
AdoQuery1.SQL.Add('insert into test(bf) values(:p)');
Adoquery1.Parameters.ParamByName('p').LoadFromFile('c:\test.doc',ftBlob);
AdoQuery1.ExecSQL;
end;
procedure TForm1.Button2Click(Sender: TObject);
var MS: TMemoryStream;
begin
AdoQuery1.Close;
AdoQuery1.SQL.Add('select * from test');
AdoQuery1.Open;
Ms:=TMemoryStream.Create;
TBlobField(AdoQuery1.FieldByName('bf')).SaveToFile('c:\outtest.doc');
end;
access数据库用ole字段,sql数据库可以用image字段
#5
还有,我把exe文件的扩展名改成其他比如ttt,怎么在程序中打开这样的文件 *.ttt
这个有人知道吗
这个有人知道吗
#6
把名字改回来啊
#7
呵呵,好兄弟,我还有一个问题,在向数据库中提交数据的时候(上传,下载的时候),怎样添加进程条
#8
按流处理可以不?
#9
这是我现在用的代码。带进度条...
procedure TfrmUpdate.DownLoadPro; //从数据库的表中下载
const
MaxBufSize = $F000;
var
myfilename:string;//保存文件的路径和文件名
myfileStream,exeBlobStream: TStream;
Count,BufSize, N: Integer;
Buffer: PChar;
begin
with AdoUpdate do
begin
Open;
Edit;
myfilename := ExtractFilePath(Application.ExeName) + FieldByName('F_Appname').AsString;//获得文件的完整路径
myfileStream := TFileStream.Create(myfilename, fmCreate);//创建文件
try //SaveToStream(Stream);
ExeBlobStream := CreateBlobStream(FieldByName('F_FileStream'), bmRead); //从数据库中取得记录
Count := 0;
try
if Count = 0 then
begin
ExeBlobStream.Position := 0;
Count := ExeBlobStream.Size;//showmessage(inttostr(count));
end;
if Count > MaxBufSize then BufSize := MaxBufSize else BufSize := Count;
GetMem(Buffer, BufSize);
ProgressBar1.Position := 0;
ProgressBar1.Max := count div bufsize;//每次写入文件的数据流大小为bufsize,所以max为count 除以 bufsize
try
while Count <> 0 do
begin
if Count > BufSize then N := BufSize else N := Count;
ExeBlobStream.ReadBuffer(Buffer^, N);//从数据库表中取数据流
MyFileStream.WriteBuffer(Buffer^, N);//将数据流写入文件
Dec(Count, N);
ProgressBar1.Position := ProgressBar1.Position + 1;
end;
finally
FreeMem(Buffer, BufSize);
end;
finally
ExeBlobStream.Free;
end;
finally
myfileStream.Free;
end;
end;
MessageBox(Handle,pchar('软件升级完成,现在可以重新XXXX系统了 '),'信息',MB_ICONINFORMATION);
end;
下面的上传到数据库的表中
procedure TfrmUpdate.UpLoadPro;
const
BufSize = $F000;
var
Counter, N: Integer;
Buffer: PAnsiChar;
FieldStrm: TStream;
ExeFileStream:TFileStream;
size_tmp: Double;
begin
with AdoUpdate do
begin
Open;
Edit;
try
ExeFileStream:=TFileStream.Create('XXXXX.exe',fmopenRead); //打开文件
FieldStrm := CreateBlobStream(FieldByName('F_FileStream'), bmWrite);
GetMem(Buffer, BufSize);
try
Counter := ExeFileStream.Size;
size_tmp := ExeFileStream.Size;
ProgressBar1.Position := 0;
ProgressBar1.Max := Counter div BufSize; //每次上传文件流为61440 byte = $F000
while Counter <> 0 do
begin
if Counter > BufSize then
N := BufSize
else
N := Counter;
ExeFileStream.ReadBuffer(Buffer^, N);
FieldStrm.WriteBuffer(Buffer^, N);
Dec(Counter, N);
ProgressBar1.Position := ProgressBar1.Position + 1;
Application.ProcessMessages;
end;
finally
FreeMem(Buffer, BufSize);
FieldStrm.Free;
end;
FieldByName('F_Version').AsString:=iniVersion;
FieldByName('F_Size').AsFloat:=size_tmp;
FieldByName('F_UpdateTime').AsDateTime:=now();
Post;
Application.MessageBox('新版本程序上传至服务器成功!','提示',MB_OK+MB_IconInformation);
finally
ProgressBar1.Position := ProgressBar1.Max;
ExeFileStream.Free;
CanLeave:=True;
end;
end;
end;
procedure TfrmUpdate.DownLoadPro; //从数据库的表中下载
const
MaxBufSize = $F000;
var
myfilename:string;//保存文件的路径和文件名
myfileStream,exeBlobStream: TStream;
Count,BufSize, N: Integer;
Buffer: PChar;
begin
with AdoUpdate do
begin
Open;
Edit;
myfilename := ExtractFilePath(Application.ExeName) + FieldByName('F_Appname').AsString;//获得文件的完整路径
myfileStream := TFileStream.Create(myfilename, fmCreate);//创建文件
try //SaveToStream(Stream);
ExeBlobStream := CreateBlobStream(FieldByName('F_FileStream'), bmRead); //从数据库中取得记录
Count := 0;
try
if Count = 0 then
begin
ExeBlobStream.Position := 0;
Count := ExeBlobStream.Size;//showmessage(inttostr(count));
end;
if Count > MaxBufSize then BufSize := MaxBufSize else BufSize := Count;
GetMem(Buffer, BufSize);
ProgressBar1.Position := 0;
ProgressBar1.Max := count div bufsize;//每次写入文件的数据流大小为bufsize,所以max为count 除以 bufsize
try
while Count <> 0 do
begin
if Count > BufSize then N := BufSize else N := Count;
ExeBlobStream.ReadBuffer(Buffer^, N);//从数据库表中取数据流
MyFileStream.WriteBuffer(Buffer^, N);//将数据流写入文件
Dec(Count, N);
ProgressBar1.Position := ProgressBar1.Position + 1;
end;
finally
FreeMem(Buffer, BufSize);
end;
finally
ExeBlobStream.Free;
end;
finally
myfileStream.Free;
end;
end;
MessageBox(Handle,pchar('软件升级完成,现在可以重新XXXX系统了 '),'信息',MB_ICONINFORMATION);
end;
下面的上传到数据库的表中
procedure TfrmUpdate.UpLoadPro;
const
BufSize = $F000;
var
Counter, N: Integer;
Buffer: PAnsiChar;
FieldStrm: TStream;
ExeFileStream:TFileStream;
size_tmp: Double;
begin
with AdoUpdate do
begin
Open;
Edit;
try
ExeFileStream:=TFileStream.Create('XXXXX.exe',fmopenRead); //打开文件
FieldStrm := CreateBlobStream(FieldByName('F_FileStream'), bmWrite);
GetMem(Buffer, BufSize);
try
Counter := ExeFileStream.Size;
size_tmp := ExeFileStream.Size;
ProgressBar1.Position := 0;
ProgressBar1.Max := Counter div BufSize; //每次上传文件流为61440 byte = $F000
while Counter <> 0 do
begin
if Counter > BufSize then
N := BufSize
else
N := Counter;
ExeFileStream.ReadBuffer(Buffer^, N);
FieldStrm.WriteBuffer(Buffer^, N);
Dec(Counter, N);
ProgressBar1.Position := ProgressBar1.Position + 1;
Application.ProcessMessages;
end;
finally
FreeMem(Buffer, BufSize);
FieldStrm.Free;
end;
FieldByName('F_Version').AsString:=iniVersion;
FieldByName('F_Size').AsFloat:=size_tmp;
FieldByName('F_UpdateTime').AsDateTime:=now();
Post;
Application.MessageBox('新版本程序上传至服务器成功!','提示',MB_OK+MB_IconInformation);
finally
ProgressBar1.Position := ProgressBar1.Max;
ExeFileStream.Free;
CanLeave:=True;
end;
end;
end;
#10
楼上高人,比我快,新年快乐!!方法不错,
#1
二进制
#2
就当成一个文件来存放吧
#3
哪位GG给段代码啊
#4
procedure TForm1.Button1Click(Sender: TObject);
begin
AdoQuery1.SQL.Add('insert into test(bf) values(:p)');
Adoquery1.Parameters.ParamByName('p').LoadFromFile('c:\test.doc',ftBlob);
AdoQuery1.ExecSQL;
end;
procedure TForm1.Button2Click(Sender: TObject);
var MS: TMemoryStream;
begin
AdoQuery1.Close;
AdoQuery1.SQL.Add('select * from test');
AdoQuery1.Open;
Ms:=TMemoryStream.Create;
TBlobField(AdoQuery1.FieldByName('bf')).SaveToFile('c:\outtest.doc');
end;
access数据库用ole字段,sql数据库可以用image字段
begin
AdoQuery1.SQL.Add('insert into test(bf) values(:p)');
Adoquery1.Parameters.ParamByName('p').LoadFromFile('c:\test.doc',ftBlob);
AdoQuery1.ExecSQL;
end;
procedure TForm1.Button2Click(Sender: TObject);
var MS: TMemoryStream;
begin
AdoQuery1.Close;
AdoQuery1.SQL.Add('select * from test');
AdoQuery1.Open;
Ms:=TMemoryStream.Create;
TBlobField(AdoQuery1.FieldByName('bf')).SaveToFile('c:\outtest.doc');
end;
access数据库用ole字段,sql数据库可以用image字段
#5
还有,我把exe文件的扩展名改成其他比如ttt,怎么在程序中打开这样的文件 *.ttt
这个有人知道吗
这个有人知道吗
#6
把名字改回来啊
#7
呵呵,好兄弟,我还有一个问题,在向数据库中提交数据的时候(上传,下载的时候),怎样添加进程条
#8
按流处理可以不?
#9
这是我现在用的代码。带进度条...
procedure TfrmUpdate.DownLoadPro; //从数据库的表中下载
const
MaxBufSize = $F000;
var
myfilename:string;//保存文件的路径和文件名
myfileStream,exeBlobStream: TStream;
Count,BufSize, N: Integer;
Buffer: PChar;
begin
with AdoUpdate do
begin
Open;
Edit;
myfilename := ExtractFilePath(Application.ExeName) + FieldByName('F_Appname').AsString;//获得文件的完整路径
myfileStream := TFileStream.Create(myfilename, fmCreate);//创建文件
try //SaveToStream(Stream);
ExeBlobStream := CreateBlobStream(FieldByName('F_FileStream'), bmRead); //从数据库中取得记录
Count := 0;
try
if Count = 0 then
begin
ExeBlobStream.Position := 0;
Count := ExeBlobStream.Size;//showmessage(inttostr(count));
end;
if Count > MaxBufSize then BufSize := MaxBufSize else BufSize := Count;
GetMem(Buffer, BufSize);
ProgressBar1.Position := 0;
ProgressBar1.Max := count div bufsize;//每次写入文件的数据流大小为bufsize,所以max为count 除以 bufsize
try
while Count <> 0 do
begin
if Count > BufSize then N := BufSize else N := Count;
ExeBlobStream.ReadBuffer(Buffer^, N);//从数据库表中取数据流
MyFileStream.WriteBuffer(Buffer^, N);//将数据流写入文件
Dec(Count, N);
ProgressBar1.Position := ProgressBar1.Position + 1;
end;
finally
FreeMem(Buffer, BufSize);
end;
finally
ExeBlobStream.Free;
end;
finally
myfileStream.Free;
end;
end;
MessageBox(Handle,pchar('软件升级完成,现在可以重新XXXX系统了 '),'信息',MB_ICONINFORMATION);
end;
下面的上传到数据库的表中
procedure TfrmUpdate.UpLoadPro;
const
BufSize = $F000;
var
Counter, N: Integer;
Buffer: PAnsiChar;
FieldStrm: TStream;
ExeFileStream:TFileStream;
size_tmp: Double;
begin
with AdoUpdate do
begin
Open;
Edit;
try
ExeFileStream:=TFileStream.Create('XXXXX.exe',fmopenRead); //打开文件
FieldStrm := CreateBlobStream(FieldByName('F_FileStream'), bmWrite);
GetMem(Buffer, BufSize);
try
Counter := ExeFileStream.Size;
size_tmp := ExeFileStream.Size;
ProgressBar1.Position := 0;
ProgressBar1.Max := Counter div BufSize; //每次上传文件流为61440 byte = $F000
while Counter <> 0 do
begin
if Counter > BufSize then
N := BufSize
else
N := Counter;
ExeFileStream.ReadBuffer(Buffer^, N);
FieldStrm.WriteBuffer(Buffer^, N);
Dec(Counter, N);
ProgressBar1.Position := ProgressBar1.Position + 1;
Application.ProcessMessages;
end;
finally
FreeMem(Buffer, BufSize);
FieldStrm.Free;
end;
FieldByName('F_Version').AsString:=iniVersion;
FieldByName('F_Size').AsFloat:=size_tmp;
FieldByName('F_UpdateTime').AsDateTime:=now();
Post;
Application.MessageBox('新版本程序上传至服务器成功!','提示',MB_OK+MB_IconInformation);
finally
ProgressBar1.Position := ProgressBar1.Max;
ExeFileStream.Free;
CanLeave:=True;
end;
end;
end;
procedure TfrmUpdate.DownLoadPro; //从数据库的表中下载
const
MaxBufSize = $F000;
var
myfilename:string;//保存文件的路径和文件名
myfileStream,exeBlobStream: TStream;
Count,BufSize, N: Integer;
Buffer: PChar;
begin
with AdoUpdate do
begin
Open;
Edit;
myfilename := ExtractFilePath(Application.ExeName) + FieldByName('F_Appname').AsString;//获得文件的完整路径
myfileStream := TFileStream.Create(myfilename, fmCreate);//创建文件
try //SaveToStream(Stream);
ExeBlobStream := CreateBlobStream(FieldByName('F_FileStream'), bmRead); //从数据库中取得记录
Count := 0;
try
if Count = 0 then
begin
ExeBlobStream.Position := 0;
Count := ExeBlobStream.Size;//showmessage(inttostr(count));
end;
if Count > MaxBufSize then BufSize := MaxBufSize else BufSize := Count;
GetMem(Buffer, BufSize);
ProgressBar1.Position := 0;
ProgressBar1.Max := count div bufsize;//每次写入文件的数据流大小为bufsize,所以max为count 除以 bufsize
try
while Count <> 0 do
begin
if Count > BufSize then N := BufSize else N := Count;
ExeBlobStream.ReadBuffer(Buffer^, N);//从数据库表中取数据流
MyFileStream.WriteBuffer(Buffer^, N);//将数据流写入文件
Dec(Count, N);
ProgressBar1.Position := ProgressBar1.Position + 1;
end;
finally
FreeMem(Buffer, BufSize);
end;
finally
ExeBlobStream.Free;
end;
finally
myfileStream.Free;
end;
end;
MessageBox(Handle,pchar('软件升级完成,现在可以重新XXXX系统了 '),'信息',MB_ICONINFORMATION);
end;
下面的上传到数据库的表中
procedure TfrmUpdate.UpLoadPro;
const
BufSize = $F000;
var
Counter, N: Integer;
Buffer: PAnsiChar;
FieldStrm: TStream;
ExeFileStream:TFileStream;
size_tmp: Double;
begin
with AdoUpdate do
begin
Open;
Edit;
try
ExeFileStream:=TFileStream.Create('XXXXX.exe',fmopenRead); //打开文件
FieldStrm := CreateBlobStream(FieldByName('F_FileStream'), bmWrite);
GetMem(Buffer, BufSize);
try
Counter := ExeFileStream.Size;
size_tmp := ExeFileStream.Size;
ProgressBar1.Position := 0;
ProgressBar1.Max := Counter div BufSize; //每次上传文件流为61440 byte = $F000
while Counter <> 0 do
begin
if Counter > BufSize then
N := BufSize
else
N := Counter;
ExeFileStream.ReadBuffer(Buffer^, N);
FieldStrm.WriteBuffer(Buffer^, N);
Dec(Counter, N);
ProgressBar1.Position := ProgressBar1.Position + 1;
Application.ProcessMessages;
end;
finally
FreeMem(Buffer, BufSize);
FieldStrm.Free;
end;
FieldByName('F_Version').AsString:=iniVersion;
FieldByName('F_Size').AsFloat:=size_tmp;
FieldByName('F_UpdateTime').AsDateTime:=now();
Post;
Application.MessageBox('新版本程序上传至服务器成功!','提示',MB_OK+MB_IconInformation);
finally
ProgressBar1.Position := ProgressBar1.Max;
ExeFileStream.Free;
CanLeave:=True;
end;
end;
end;
#10
楼上高人,比我快,新年快乐!!方法不错,