1

I am trying to create a zip file with Delphi Tokyo using the command ZipDirectoryContents which has 4 parameters. They are

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

Is there someone who can tell me how to use these parameters especially the TZipProgressEvent to show the progress of the zip file as it is adding the files from the directory. Thanks

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
LGreen
  • 41
  • 1
  • 4
  • Please provide an accurate code example and pinpoint your issue from there. – Fabien Jul 28 '17 at 23:13
  • The sample Victoria provided below is better than I could have done, but it still seems to fail to fire the progress to update a progress bar. Anyone know why? Thanks – LGreen Jul 29 '17 at 23:57

1 Answers1

1

Here is the answer provided by 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.
LGreen
  • 41
  • 1
  • 4