如何获知正在下载的文件已下载了大小(0分)

  • 主题发起人 主题发起人 kiven_lu
  • 开始时间 开始时间
K

kiven_lu

Unregistered / Unconfirmed
GUEST, unregistred user!
在下载过程中,想添加一进度条,但不知道如何获取下载文件的已下载大小
 
function FileSize(var F): Integer;
Description
In Delphi code, call FileSize to determine the size of the file specified by the file variable F. The size is expressed as the number of records in a record file. Thus:
If the file is declared as a file of byte, then
the record size defaults to one byte, and FileSize returns the number of bytes in the file.
The Reset procedure can set the record size (in bytes) when it opens the file. In this case, FileSize returns the number of records in the file.
Note: If the file is declared as an untyped file and you do
n抰 specify a record size when you call Reset, then
FileSize assumes a record size of 128. That is, FileSize gives the number of bytes divided by 128.
To use FileSize, the file must be open. If the file is empty, FileSize(F) returns 0.
 
好不容易发现一个自己可以回答的问题,却个个都是没有分的,真是不公平。
用ICS控件吧,我以前问过这样的问题,我自己也做成了进度条。
 
var
f: file of Byte;
size: Longint;
S: string;
y: Integer;
begin
Try
IF not FileExists(Trim(Edit1.Text)) then
exit;
AssignFile(f, Trim(Edit1.Text));
Reset(f);//到这时出现“I/O error 32” 错误 ,应为文件还处于下载状态
try
size := FileSize(f);
S := 'File size in bytes: ' + IntToStr(size);
y := 10;
Canvas.TextOut(5, y, S);
y := y + Canvas.TextHeight(S) + 5;
S := 'Seeking halfway into file...';
Canvas.TextOut(5, y, S);
y := y + Canvas.TextHeight(S) + 5;
Seek(f, size div 2);
S := 'Position is now ' + IntToStr(FilePos(f));
Canvas.TextOut(5, y, S);
finally
CloseFile(f);
end;
Finally
end;
 
用ICS控件吧??但不知用什么方法了,
举个例好吗?
 
后退
顶部