AWorkCountMax
并且AWorkCount
是字节数,而不是百分比。您需要在更新 UI 时考虑到这一点,尤其是在您想显示百分比时。
话虽如此,AWorkCountMax
仅对上传有效,对下载无效。这样做的原因是因为FTP协议在传输过程中不传输文件大小,所以TIdFTP
不知道正在下载的文件的大小,只知道正在上传的本地文件的大小。对于下载,您必须先手动检索文件大小,使用TIdFTP.Size()
、TIdFTP.List()
或TIdFTP.ExtListItem()
.
并完全远离Application.ProcessMessages()
。如果要触发重绘,请Update()
改用。
尝试这个:
procedure TForm1.IdFTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64);
begin
if AWorkMode = wmWrite then
ProgressBar1.Max := AWorkCountMax
else;
ProgressBar1.Max := ...; // value retrieved beforehand...
ProgressBar1.Position := 0;
end;
procedure TForm1.IdFTP1Work(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
begin
if ProgressBar1.Max > 0 then
begin
ProgressBar1.Position := AWorkCount;
Label6.Caption := IntToStr((ProgressBar1.Position * 100) div ProgressBar1.Max) + '%';
end else
Label6.Caption := IntToStr(AWorkCount) + ' bytes';
Update;
end;
procedure TForm1.IdFTP1WorkEnd(ASender: TObject; AWorkMode: TWorkMode);
begin
ProgressBar1.Position := 0;
end;
或者:
var
WorkMax: Int64;
procedure TForm1.IdFTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64);
begin
if AWorkMode = wmWrite then
WorkMax := AWorkCountMax
else;
WorkMax := := ...; // value retrieved beforehand...
ProgressBar1.Min := 0;
ProgressBar1.Max := 100;
ProgressBar1.Position := 0;
end;
procedure TForm1.IdFTP1Work(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
begin
if WorkMax > 0 then
begin
ProgressBar1.Position := (AWorkCount * 100) div WorkMax;
Label6.Caption := IntToStr(ProgressBar1.Position) + '%';
end else
Label6.Caption := IntToStr(AWorkCount) + ' bytes';
Update;
end;
procedure TForm1.IdFTP1WorkEnd(ASender: TObject; AWorkMode: TWorkMode);
begin
ProgressBar1.Position := 0;
end;