copy和load文件时等待时间长,想加一个进度条用于显示copy 和 load 的进度,不知道怎样控制。
解决方案 »
- Delphi DBGrid 滚动条滚动不能实时显示数据?
- 怎样在stringgrid中设置单元格的背景颜色、字体颜色
- 控制DBGrid的光标移动。
- 急~~请问如何在程序的客户区绘制数据曲线?
- procedure WMNID(var msg:TMessage);message wm_nid;问题??
- 关于注册码的问题。大虾请进
- 关于SOCKET发送不出数据的问题
- 如何接收文本文件的数据到db2数据库中
- 我的报表预览正常,打印却只卷一下纸,打印就结束,打印机设置都正确!
- delphi的treeview上的checkbox怎么设置成不能够选择打勾,且变成灰色
- password form main form 160分!!!160分!!!
- 请您解答:delphi多线程例程
procedure TMainForm.btnCopyClick(Sender: TObject);
var
SrcFile, DestFile: File;
BytesRead, BytesWritten, TotalRead: Integer;
Buffer: array[1..500] of byte;
FSize: Integer;
begin
{ Assign both the source and destination files to their
respective file variables }
AssignFile(SrcFile, 'srcfile.tst');
AssignFile(DestFile, 'destfile.tst');
// Open the source file for read access.
Reset(SrcFile, 1);
try
// Open destination file for write access.
Rewrite(DestFile, 1);
try
{ Encapsulate this into a try..except so that we can erase the file if
an error occurs. }
try
// Initialize total bytes read to zero.
TotalRead := 0;
// Obtain the filesize of the source file
FSize := FileSize(SrcFile);
{ Read SizeOf(Buffer) bytes from the source file
and add these bytes to the destination file. Repeat this
process until all bytes have been read from the source
file. A progress bar is provided to show the progress of the
copy operation. }
repeat
BlockRead(SrcFile, Buffer, SizeOf(Buffer), BytesRead);
if BytesRead > 0 then
begin
BlockWrite(DestFile, Buffer, BytesRead, BytesWritten);
if BytesRead <> BytesWritten then
raise Exception.Create('Error copying file')
else begin
TotalRead := TotalRead + BytesRead;
prbCopy.Position := Trunc(TotalRead / Fsize) * 100;
prbCopy.Update;
end;
end
until BytesRead = 0;
except
{ On an exception, erase the destination file as it may be
corrupt. Then re-raise the exception. }
Erase(DestFile);
raise;
end;
finally
CloseFile(DestFile); // Close the destination file.
end;
finally
CloseFile(SrcFile); // Close the source file.
end;
end;