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

  1. unit tziplist;
  2.  
  3. interface
  4.  
  5. uses
  6.   Wintypes, Winprocs, Messages, SysUtils, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, ZipDir, Grids, ExtCtrls, SortGrid;
  8.  
  9. type
  10.   TZipForm = class(TForm)
  11.     OpenDialog1: TOpenDialog;
  12.     Panel1: TPanel;
  13.     Button2: TButton;
  14.     ZipFNameLabel: TLabel;
  15.     StringGrid1: TSortGrid;
  16.     Label1: TLabel;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure Button2Click(Sender: TObject);
  19.     procedure FormActivate(Sender: TObject);
  20.     procedure StringGrid1BeginSort(Sender: TObject; Col: Longint;
  21.                                   var SortOptions: TSortOptions);
  22.     procedure FormDestroy(Sender: TObject);
  23.     procedure FillGrid;
  24.   private
  25.     { Private declarations }
  26.   public
  27.    { Public declarations }
  28. end;
  29.  
  30. var
  31.   ZipForm: TZipForm;
  32.   ZipDir1: TZipDir;
  33.  
  34. implementation
  35.  
  36. uses Unit1;
  37. {$R *.DFM}
  38.  
  39. procedure TZipForm.FormCreate(Sender: TObject);
  40. begin
  41.   with StringGrid1 do
  42.   begin
  43.     RowCount:=1;  { first row is fixed, and used for titles }
  44.     ColCount:=4;
  45.     Cells[0,0] := 'File Name';
  46.     Cells[1,0] := 'Compr Size';
  47.     Cells[2,0] := 'Uncmpr Size';
  48.     Cells[3,0] := 'Date/Time';
  49.   end;
  50.   ZipDir1:=TZipDir.Create(self);
  51.   if ZipDir1 = nil then
  52.   begin
  53.      ShowMessage('Error creating ZipDir1');
  54.      close;
  55.   end;
  56. end;
  57.  
  58. procedure TZipForm.FillGrid;
  59. var
  60.   i: Integer;
  61. begin
  62.   with StringGrid1 do
  63.   begin
  64.     { Empty data from string grid }
  65.     FixedRows:=0;
  66.     RowCount:=1; { remove everything from grid except col titles }
  67.     if ZipDir1.Count = 0 then
  68.        Exit;
  69.  
  70.     for i:=0 to ZipDir1.Count-1 do
  71.     begin
  72.        RowCount := RowCount + 1;
  73.        { We have to set fixed rows after the rowcount is more than 1}
  74.        FixedRows:=1;
  75.        with ZipDirEntry(ZipDir1.ZipContents[i]^) do
  76.        begin
  77.           { The "-1" below is an offset for the row titles }
  78.           Cells[0,RowCount-1] := FileName;
  79.           Cells[1,RowCount-1] := IntToStr(CompressedSize);
  80.           Cells[2,RowCount-1] := IntToStr(UncompressedSize);
  81.           Cells[3,RowCount-1] := FormatDateTime('ddddd  t',FileDateToDateTime(DateTime));
  82.        end; // end with
  83.     end; // end for
  84.   end; // end with
  85. end;
  86.  
  87. procedure TZipForm.Button2Click(Sender: TObject);
  88. begin
  89.   Close;
  90. end;
  91.  
  92. procedure TZipForm.FormActivate(Sender: TObject);
  93. begin
  94.    Width:=Form1.Width;
  95.    Height:=Form1.Height;
  96.    Top:=Form1.Top;
  97.    Left:=Form1.Left;
  98.    ZipFNameLabel.Caption:=Form1.ZipFName.Caption;
  99.    with StringGrid1 do
  100.    begin
  101.       FixedRows:=0;
  102.       RowCount:=1; { remove everything from grid except col titles }
  103.       ColWidths[0]:=316;
  104.       ColWidths[1]:=84;
  105.       ColWidths[2]:=84;
  106.       ColWidths[3]:=120;
  107.    end;
  108.  
  109.    if FileExists(Form1.ZipFName.Caption) then
  110.       { This assignment causes zipfile to be read: }
  111.       ZipDir1.ZipFileName := Form1.ZipFName.Caption
  112.    else
  113.    begin
  114.       ShowMessage('Error - file not found: ' + Form1.ZipFName.Caption);
  115.       Close;
  116.    end;
  117.    FillGrid;
  118. end;
  119.  
  120. { This just shows you which column, datatype, and sort order will be used. }
  121. { This is keyed from the SortGrid's OnBeginSort event. }
  122. { You can remove this if you want. }
  123. procedure TZipForm.StringGrid1BeginSort(Sender: TObject; Col: Longint;
  124.           var SortOptions: TSortOptions);
  125. var
  126.   Order: String;
  127.   ColName: String;
  128. begin
  129.   if SortOptions.SortDirection=sdAscending then
  130.      Order:='Ascending'
  131.   else
  132.      Order:='Descending';
  133.   ColName:=StringGrid1.Cells[Col,0];
  134.   case SortOptions.SortStyle of
  135.      ssNumeric:  ShowMessage('Sorting By ' + ColName + ', Numeric, ' + Order);
  136.      ssDateTime: ShowMessage('Sorting By ' + ColName + ', Datetime, ' + Order);
  137.      ssTime:     ShowMessage('Sorting By ' + ColName + ', Time, ' + Order);
  138.      ssCustom:   ShowMessage('Sorting By ' + ColName + ', Custom, ' + Order);
  139.   else
  140.      ShowMessage('Sorting By ' + ColName + ', Alpha, ' + Order);
  141.   end;
  142. end;
  143.  
  144. procedure TZipForm.FormDestroy(Sender: TObject);
  145. begin
  146.    ZipDir1.Free;
  147. end;
  148.  
  149. end.
  150.