使用Delphi Toyko在流程示例中创建一个Zip文件 [英] Using Delphi Toyko creating a Zip file onprocess example
本文介绍了使用Delphi Toyko在流程示例中创建一个Zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用带有4个参数的命令ZipDirectoryContents与Delphi Tokyo创建一个zip文件.他们是
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;
有人可以告诉我如何使用这些参数,尤其是TZipProgressEvent来显示zip文件的进度,因为它是从目录中添加文件的.谢谢
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
推荐答案
以下是Embarcadero提供的答案
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.
这篇关于使用Delphi Toyko在流程示例中创建一个Zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文