Using Delphi Toyko creating a Zip file onprocess example

╄→尐↘猪︶ㄣ 提交于 2019-12-12 04:57:08

问题


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


回答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.


来源:https://stackoverflow.com/questions/45383554/using-delphi-toyko-creating-a-zip-file-onprocess-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!