TurboPower Abbrevia 是一套for Embarcadero Delphi, C++Builder 程式開發工具上的壓縮軟體工具。

 

從Delphi 6所使用的Vclzip 無法繼續在Delphi XE2使用。

於是找到這套FREEWARE的壓縮軟體。

官網:http://sourceforge.net/projects/tpabbrevia/

下載:http://sourceforge.net/projects/tpabbrevia/files/latest/download

 

咦!! Delphi XE2不是有Native的壓縮軟體 TZIPFILE,但是發現java.util.zip 壓出來的zip(ZLIB格式)不行解壓縮。(希望下個版本能提供修正)

Embarcadero Bug report:TZipFile: zip extracted with 0-size files.
http://qc.embarcadero.com/wc/qcmain.aspx?da=128 顯示Zip蠻多Bug尚未解決(101/3/17 updated)

 

紀錄Abbrevia幾個使用壓縮及解壓縮的程式碼範例。

unit Unit1; 

interface 

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AbZipper, Vcl.StdCtrls, AbUnzper,
  AbUtils; 

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    BtnZipOne: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit5: TEdit;
    Label5: TLabel;
    BtnZipFolder: TButton;
    BtnUnzip: TButton;
    Label6: TLabel;
    Edit6: TEdit;
    Memo1: TMemo;
    procedure BtnZipOneClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BtnZipFolderClick(Sender: TObject);
    procedure BtnUnzipClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end; 

var
  Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.BtnZipOneClick(Sender: TObject);
VAR
  oZip: TAbZipper; // uses  AbZipper
begin
{壓縮一個檔案}
  oZip := TAbZipper.Create(self);
  try
    oZip.FileName := Edit4.Text; // 'c:\test1.zip';
    // oZip.BaseDirectory := 'c:\temp\';
    oZip.DeleteFiles('*.*'); // 清除zip內所有檔案
    oZip.AddFiles(Edit1.Text, faAnyFile);
    oZip.Save;
    Memo1.Lines.Add(Edit1.Text + ' zip to ' + Edit4.Text);
  finally
    freeandNil(oZip);
  end;
end; 

procedure TForm1.BtnZipFolderClick(Sender: TObject);
VAR
  oZip: TAbZipper; // uses  AbZipper
begin
{壓縮一個目錄}
  oZip := TAbZipper.Create(self);
  try
    oZip.FileName := Edit5.Text; // 'c:\test1.zip';
    oZip.BaseDirectory := Edit2.Text;  // 'c:\auto\
    oZip.DeleteFiles('*.*'); // 清除zip內所有檔案
    oZip.AddFiles('*', faAnyFile);
    oZip.Save;
    Memo1.Lines.Add(Edit2.Text + ' zip to ' + Edit5.Text);
  finally
    freeandNil(oZip);
  end; 

end; 

procedure TForm1.BtnUnzipClick(Sender: TObject);
var
  AbUnZip: TAbUnZipper; // uses AbUnzper
  aPath: string;
begin
{解壓縮檔案}
  AbUnZip := TAbUnZipper.Create(nil);
  try
      //unzip 包含路徑也一併解
    AbUnZip.ExtractOptions := oAbUnZipper.ExtractOptions +[eoRestorePath];
    AbUnZip.FileName := Edit3.Text; // c:\test3.zip
    aPath := Edit6.Text; // 'c:\temp\a1\';
    AbUtils.AbCreateDirectory(aPath); // 不會自己建目錄,須自己來 uses AbUtils
    AbUnZip.BaseDirectory := aPath; // set BaseDirectory 若目錄不存在會報錯
    AbUnZip.ExtractFiles('*.*');
    Memo1.Lines.Add(Edit3.Text + ' unzip to ' + Edit6.Text);
  finally
    freeandNil(AbUnZip);
  end;
end; 

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Lines.Clear;
end; 

end.


Abbrevia

arrow
arrow

    味味A 發表在 痞客邦 留言(0) 人氣()