2017-07-28 75 views
-1

我想使用帶有4個參數的命令ZipDirectoryContents使用Delphi東京創建一個zip文件。他們是使用Delphi Toyko在過程示例中創建一個Zip文件

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

有沒有誰可以告訴我如何使用這些參數尤其是TZipProgressEvent顯示zip文件的進度,因爲它是從目錄添加文件。由於

+0

請提供準確的代碼示例,並從那裏找出具體的問題。 – Fabien

+0

維多利亞在下面提供的樣本比我能做的要好,但它似乎仍未能啓動更新進度條的進度。有人知道爲什麼謝謝 – LGreen

回答

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. 
+0

你應該使用線程。如果這是產品支持的答案,那麼,呃... – Victoria

相關問題