home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / Chip_1998-03_cd.bin / zkuste / delphi / komprese / zip / DELZIP12.ZIP / DEMO2.ZIP / UNIT1.PAS < prev    next >
Pascal/Delphi Source File  |  1997-09-28  |  4KB  |  125 lines

  1. unit Unit1;   { DEMO 2 for Delphi Zip by Eric W. Engler }
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ZipMstr;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     ZipBut: TButton;
  12.     UnzipBut: TButton;
  13.     ExitBut: TButton;
  14.     DelBut: TButton;
  15.     VersionBut: TButton;
  16.     ZipMaster1: TZipMaster;
  17.     procedure ZipButClick(Sender: TObject);
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure ExitButClick(Sender: TObject);
  20.     procedure ZipMaster1Message(Sender: TObject; ErrCode: Integer;
  21.       Message: string);
  22.     procedure UnzipButClick(Sender: TObject);
  23.     procedure DelButClick(Sender: TObject);
  24.     procedure VersionButClick(Sender: TObject);
  25.     procedure FormDestroy(Sender: TObject);
  26.   private
  27.     { Private declarations }
  28.   public
  29.     { Public declarations }
  30.   end;
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35. implementation
  36.  
  37. {$R *.DFM}
  38.  
  39. procedure TForm1.FormCreate(Sender: TObject);
  40. begin
  41.    { SetCurrentDir('C:\ZIP\DEMO2'); }
  42.    Caption:='ZIP Demo 2 - ' + GetCurrentDir;
  43.    ZipMaster1.ZipFileName:='TEST.ZIP';
  44.    ZipMaster1.Load_Zip_Dll;
  45.    ZipMaster1.Load_Unz_Dll;
  46. end;
  47.  
  48. { Add one file to the zipfile }
  49. procedure TForm1.ZipButClick(Sender: TObject);
  50. begin
  51.    if not FileExists('TEST.DAT') then
  52.    begin
  53.       ShowMessage('Error - test.dat not found');
  54.       Exit;
  55.    end;
  56.    ZipMaster1.FSpecArgs.Add('TEST.DAT');
  57.    ZipMaster1.Add;
  58.    ShowMessage('Files added = ' + IntToStr(ZipMaster1.SuccessCnt));
  59. end;
  60.  
  61. { expand all files from the zipfile }
  62. procedure TForm1.UnzipButClick(Sender: TObject);
  63. begin
  64.   with ZipMaster1 do
  65.   begin
  66.      if Count = 0 then
  67.      begin
  68.         ShowMessage('Error - no files in the Zip file');
  69.         Exit;
  70.      end;
  71.      { If we don't specify filenames, we will extract them all. }
  72.      { Of course, in this little demo there is only 1 file in the ZIP. }
  73.      FSpecArgs.Add('TEST.DAT');
  74.      ExtrBaseDir:=GetCurrentDir;
  75.      { if the file to be extracted already exists, overwrite it }
  76.      ExtrOptions:=ExtrOptions+[ExtrOverwrite];
  77.      Extract;
  78.      ShowMessage('Files extracted = ' + IntToStr(SuccessCnt));
  79.   end;
  80. end;
  81.  
  82. { delete one file from the zipfile }
  83. procedure TForm1.DelButClick(Sender: TObject);
  84. begin
  85.    ZipMaster1.FSpecArgs.Add('TEST.DAT');
  86.    ZipMaster1.Delete;
  87.    ShowMessage('Files deleted = ' + IntToStr(ZipMaster1.SuccessCnt));
  88. end;
  89.  
  90. procedure TForm1.VersionButClick(Sender: TObject);
  91. begin
  92.    ShowMessage('ZIPDLL version: ' + IntToStr(ZipMaster1.ZipVers)
  93.       + #13#10#13#10 + 'UNZDLL version: '
  94.       + IntToStr(ZipMaster1.UnzVers));
  95. end;
  96.  
  97. procedure TForm1.ExitButClick(Sender: TObject);
  98. begin
  99.    Close;
  100. end;
  101.  
  102. { This procedure displays messages received from the DLLs.  If you really
  103.   want to minimize the amount of messages you show the user, you don't
  104.   even need to assign this event handler.  However, I'd still recommend
  105.   that you assign this to catch errors.  You can test the ErrCode
  106.   before you display the message - if ErrCode is non-zero, make sure you
  107.   display the message.  If it's 0, then you can ignore the message.
  108.     Also, if ZipMaster1's "Verbose" property if true, you'll get more
  109.   informational message callbacks here. By default, it's false to
  110.   minimize user messages. }
  111. procedure TForm1.ZipMaster1Message(Sender: TObject; ErrCode: Integer;
  112.   Message: string);
  113. begin
  114.    { if ErrCode <> 0 then }   { uncomment this line to show errors ONLY }
  115.    ShowMessage(Message);
  116. end;
  117.  
  118. procedure TForm1.FormDestroy(Sender: TObject);
  119. begin
  120.    ZipMaster1.Unload_Zip_Dll;
  121.    ZipMaster1.Unload_Unz_Dll;
  122. end;
  123.  
  124. end.
  125.