Subversion Repositories autosfx

Rev

Blame | Last modification | View Log | RSS feed

  1. unit Unit1;   { DEMO 2 for Delphi Zip by Eric W. Engler }
  2. (************************************************************************
  3.  Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht,
  4.       Eric W. Engler and Chris Vleghert.
  5.  
  6.    This file is part of TZipMaster Version 1.9.
  7.  
  8.     TZipMaster is free software: you can redistribute it and/or modify
  9.     it under the terms of the GNU Lesser General Public License as published by
  10.     the Free Software Foundation, either version 3 of the License, or
  11.     (at your option) any later version.
  12.  
  13.     TZipMaster is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU Lesser General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU Lesser General Public License
  19.     along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
  20.  
  21.     contact: problems@delphizip.org (include ZipMaster in the subject).
  22.     updates: http://www.delphizip.org
  23.     DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
  24. ************************************************************************)
  25.  
  26. interface
  27.  
  28. uses
  29.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  30.   StdCtrls, ZipMstr19;
  31.  
  32. type
  33.   TForm1 = class(TForm)
  34.     ZipBut: TButton;
  35.     UnzipBut: TButton;
  36.     ExitBut: TButton;
  37.     DelBut: TButton;
  38.     VersionBut: TButton;
  39.     ZipMaster1: TZipMaster19;
  40.     procedure ZipButClick(Sender: TObject);
  41.     procedure FormCreate(Sender: TObject);
  42.     procedure ExitButClick(Sender: TObject);
  43.     procedure ZipMaster1Message(Sender: TObject; ErrCode: Integer;
  44.       Message: string);
  45.     procedure UnzipButClick(Sender: TObject);
  46.     procedure DelButClick(Sender: TObject);
  47.     procedure VersionButClick(Sender: TObject);
  48.     procedure FormDestroy(Sender: TObject);
  49.   private
  50.     { Private declarations }
  51.   public
  52.     { Public declarations }
  53.   end;
  54.  
  55. var
  56.   Form1: TForm1;
  57.  
  58. implementation
  59.  
  60. {$R *.DFM}
  61.  
  62. procedure TForm1.FormCreate(Sender: TObject);
  63. begin
  64.    { SetCurrentDir('C:\ZIP\DEMO2'); }
  65.    Caption:='ZIP Demo 2 - ' + GetCurrentDir;
  66.    ZipMaster1.ZipFileName:='test.zip';
  67.    ZipMaster1.Dll_Load := true;
  68. end;
  69.  
  70. { Add one file to the zipfile }
  71. procedure TForm1.ZipButClick(Sender: TObject);
  72. begin
  73.    if not FileExists('TEST.DAT') then
  74.    begin
  75.       ShowMessage('Error - test.dat not found');
  76.       Exit;
  77.    end;
  78.    ZipMaster1.FSpecArgs.Add('TEST.DAT');
  79.    ZipMaster1.Add;
  80.    ShowMessage('Files added = ' + IntToStr(ZipMaster1.SuccessCnt));
  81. end;
  82.  
  83. { expand all files from the zipfile }
  84. procedure TForm1.UnzipButClick(Sender: TObject);
  85. begin
  86.   with ZipMaster1 do
  87.   begin
  88.      if Count = 0 then
  89.      begin
  90.         ShowMessage('Error - no files in the Zip file');
  91.         Exit;
  92.      end;
  93.      { If we don't specify filenames, we will extract them all. }
  94.      { Of course, in this little demo there is only 1 file in the ZIP. }
  95.      FSpecArgs.Add('*.*');
  96.      ExtrBaseDir:=GetCurrentDir;
  97.      { if the file to be extracted already exists, overwrite it }
  98.      ExtrOptions:=ExtrOptions+[ExtrOverwrite];
  99.      Extract;
  100.      ShowMessage('Files extracted = ' + IntToStr(SuccessCnt));
  101.   end;
  102. end;
  103.  
  104. { delete one file from the zipfile }
  105. procedure TForm1.DelButClick(Sender: TObject);
  106. begin
  107.    ZipMaster1.FSpecArgs.Add('TEST.DAT');
  108.    ZipMaster1.Delete;
  109.    ShowMessage('Files deleted = ' + IntToStr(ZipMaster1.SuccessCnt));
  110. end;
  111.  
  112. procedure TForm1.VersionButClick(Sender: TObject);
  113. begin                                                                
  114.    ShowMessage('DelZip190.DLL version: ' + ZipMaster1.Dll_Version
  115.       + #13#10 + 'Loaded from: ' + ZipMaster1.Dll_Path
  116.    + #13#10 + 'ZipMaster version: ' + ZipMaster1.Version);//Info);
  117. end;
  118.  
  119. procedure TForm1.ExitButClick(Sender: TObject);
  120. begin
  121.    Close;
  122. end;
  123.  
  124. { This procedure displays messages received from the DLLs.  If you really
  125.   want to minimize the amount of messages you show the user, you don't
  126.   even need to assign this event handler.  However, I'd still recommend
  127.   that you assign this to catch errors.  You can test the ErrCode
  128.   before you display the message - if ErrCode is non-zero, make sure you
  129.   display the message.  If it's 0, then you can ignore the message.
  130.     Also, if ZipMaster1's "Verbose" property is true, you'll get more
  131.   informational message callbacks here. By default, it's false to
  132.   minimize user messages. }
  133. procedure TForm1.ZipMaster1Message(Sender: TObject; ErrCode: Integer;
  134.   Message: string);
  135. begin
  136.    { if ErrCode <> 0 then }   { uncomment this line to show errors ONLY }
  137.    ShowMessage(Message);
  138. end;
  139.  
  140. procedure TForm1.FormDestroy(Sender: TObject);
  141. begin
  142.   ZipMaster1.Dll_Load := false;
  143. end;
  144.  
  145. end.
  146.