本文介绍了在现有的Delphi代码中修改进度条的简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;

推荐答案

或者更好的方法是,将文件的大小累加为总大小,并按处理的字节数增加位置.

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

这篇关于在现有的Delphi代码中修改进度条的简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 01:42