1

我正在尝试使用具有 4 个参数的命令 ZipDirectoryContents 使用 Delphi Tokyo 创建一个 zip 文件。他们是

ZipDirectoryContents(const ZipFileName: string; const Path: string;
  Compression: TZipCompression = zcDeflate; 
  ZipProgress: TZipProgressEvent = nil); static;

有没有人可以告诉我如何使用这些参数,尤其是 TZipProgressEvent 来显示 zip 文件的进度,因为它正在从目录中添加文件。谢谢

4

1 回答 1

1

这是Embarcadero提供的答案

unit Unit16;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,System.Zip, Vcl.ComCtrls;

type
  TForm16 = class(TForm)
    Button1: TButton;
    ProgressBar1: TProgressBar;
    StaticText1: TStaticText;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    PreviousFilename : string;
  public
    { Public declarations }

    procedure OnZipProgressEvent (Sender: TObject; FileName: string; Header: TZipHeader; Position: Int64);
  end;

var
  Form16: TForm16;

implementation

{$R *.dfm}


procedure TForm16.Button1Click(Sender: TObject);
begin
    TZipFile.ZipDirectoryContents('C:\temp\Test.zip','c:\temp\zipTest',zcDeflate,OnZipProgressEvent);
end;

procedure TForm16.OnZipProgressEvent(Sender: TObject; FileName: string;
  Header: TZipHeader; Position: Int64);
begin
  if PreviousFilename <> FileName then
  begin
    StaticText1.Caption := ExtractFileName(FileName);
    PreviousFilename := FileName;
    ProgressBar1.Position := 0;
  end
  else
    ProgressBar1.Position := (Position * 100) div Header.UncompressedSize ;
  Application.ProcessMessages;
end;

end.
于 2017-08-11T14:31:21.327 回答