在现有的Delphi代码中修改进度条的简单方法?

发布于 2024-08-05 09:13:21 字数 1182 浏览 1 评论 0原文

我正在使用演示代码来压缩文件夹中的所有文件。但是,它的进度条显示的不是总进度,而是每个文件的进度。

是否有任何简单的方法可以修改代码,以便进度条显示总进度而不是每个文件的进度?

procedure DoProgress(Sender: TObject; Position, Total: Integer);
procedure DoCompressFile(Sender: TObject; const Filename: string);

....

procedure TJvZLibMultipleMainForm.DoCompressFile(Sender:TObject;const Filename:string);
begin
  lblFilename.Caption := Filename;
  Update;
end;

    procedure TJvZLibMultipleMainForm.btnCompressClick(Sender: TObject);
var
  z : TJvZlibMultiple;
begin
  ForceDirectories(ExtractFilePath(edFilename.Text));
  z := TJvZlibMultiple.Create(nil);
  Screen.Cursor := crHourGlass;
  try
    lblFilename.Caption := '';
    pbProgress.Position := 0;
    z.OnProgress := DoProgress;
    z.OnCompressingFile := DoCompressFile;
    z.CompressDirectory(edSrcFolder.Text,true,edFilename.Text);
  finally
    z.Free;
    Screen.Cursor := crDefault;
  end;
  pbProgress.Position := 0;
  lblFilename.Caption := 'Ready';
end;


procedure TJvZLibMultipleMainForm.DoProgress(Sender: TObject; Position, Total: Integer);
begin
  pbProgress.Max := Total;
  pbProgress.Position := Position;
  Update;
end;

I am using demo code which compresses all files in folder. However, it's progress bar displays not total progress, but progress for every file.

Is there any easy way to modify code so progress bar would display total progress and not progress for every single file?

procedure DoProgress(Sender: TObject; Position, Total: Integer);
procedure DoCompressFile(Sender: TObject; const Filename: string);

....

procedure TJvZLibMultipleMainForm.DoCompressFile(Sender:TObject;const Filename:string);
begin
  lblFilename.Caption := Filename;
  Update;
end;

    procedure TJvZLibMultipleMainForm.btnCompressClick(Sender: TObject);
var
  z : TJvZlibMultiple;
begin
  ForceDirectories(ExtractFilePath(edFilename.Text));
  z := TJvZlibMultiple.Create(nil);
  Screen.Cursor := crHourGlass;
  try
    lblFilename.Caption := '';
    pbProgress.Position := 0;
    z.OnProgress := DoProgress;
    z.OnCompressingFile := DoCompressFile;
    z.CompressDirectory(edSrcFolder.Text,true,edFilename.Text);
  finally
    z.Free;
    Screen.Cursor := crDefault;
  end;
  pbProgress.Position := 0;
  lblFilename.Caption := 'Ready';
end;


procedure TJvZLibMultipleMainForm.DoProgress(Sender: TObject; Position, Total: Integer);
begin
  pbProgress.Max := Total;
  pbProgress.Position := Position;
  Update;
end;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吲‖鸣 2024-08-12 09:13:21

或者更好的是,将文件的大小添加到总大小中,并按处理的字节数增加位置。

Or better yet, add up the size of the files to a total size and increment position by the number of bytes processed.

别忘他 2024-08-12 09:13:21

一种简单的方法是使用 Findfirst 和 Findnext 计算目录中的文件,然后将 pbProgress.Max 设置为该值,然后在 DoCompressFile 中将 pcProgress.Position 加 1。

A simple approach would be counting the files in the directory with Findfirst and Findnext, then setting pbProgress.Max to that and then incrementing pcProgress.Position by 1 in DoCompressFile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文