找传奇、传世资源到传世资源站!

7Z调用实例代码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

【例子介绍】7Z调用实例代码XE3
【相关图片】7Z调用实例代码 Pascal编程基础-第1张

【源码结构】

unit Form_Main;

interface

uses
  Windows, Messages, SysUtils, Variants,
  Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, ComCtrls;

type
  TFormMain = class(TForm)
    memoOutput: TMemo;
    btnAddFiles: TButton;
    btnCompress: TButton;
    btnExtract: TButton;
    OpenDialog: TOpenDialog;
    ProgressBar: TProgressBar;
    procedure btnAddFilesClick(Sender: TObject);
    procedure btnCompressClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnExtractClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormMain: TFormMain;

implementation

{$R *.dfm}

uses sevenzip;

function ProgressCallback(Sender: Pointer; total: boolean; value: int64)
  : HRESULT; stdcall;
begin
  if total then
    FormMain.ProgressBar.Max := value
  else
    FormMain.ProgressBar.Position := value;
  Result := S_OK;
end;

procedure TFormMain.btnAddFilesClick(Sender: TObject);
var
  Counter: Integer;
begin
  if OpenDialog.Execute() then
  begin
    for Counter := 0 to OpenDialog.Files.Count - 1 do
    begin
      memoOutput.Lines.Append(OpenDialog.Files[Counter]);
    end;
  end;
end;

procedure TFormMain.btnCompressClick(Sender: TObject);
var
  Arch: I7zOutArchive;
  Counter: Integer;
begin
  if OpenDialog.Files.Count = 0 then
  begin
    ShowMessage('请添加文件');
    Exit;
  end;
  memoOutput.Lines.Append('开始压缩');
  Arch := CreateOutArchive(CLSID_CFormat7z);
  Arch.SetProgressCallback(nil, ProgressCallback);
  for Counter := 0 to OpenDialog.Files.Count - 1 do
    Arch.AddFile(OpenDialog.Files[Counter],
      ExtractFileName(OpenDialog.Files[Counter]));
  SetCompressionLevel(Arch, 5);
  SevenZipSetCompressionMethod(Arch, m7Deflate64);
  Arch.SaveToFile('.\test.7z');
  memoOutput.Lines.Append('完成压缩');
  Arch := nil;
end;

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复