⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 DELPHI的压缩控件,非常实用的第三方控件
💻 PAS
字号:
Unit Unit1;

Interface

Uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ztvregister, ztvbase, ztvZipTV, ztvZipView, ztvStreams, StdCtrls,
  ExtCtrls, ComCtrls, Menus;

Type
  TForm1 = Class(TForm)
    ZipView1: TZipView;
    ZipTV1: TZipTV;
    Panel1: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    MainMenu1: TMainMenu;
    mnuErrorMessages1: TMenuItem;
    Label1: TLabel;
    Label2: TLabel;
    Procedure ZipTV1Read(Sender: TObject; Offset, Filenum: Integer);
    Procedure Button1Click(Sender: TObject);
    Procedure ZipTV1Error(Sender: TObject; FileName, ExtendedMsg,
      VolumeID: String; ECode: Integer);
    Procedure mnuErrorMessages1Click(Sender: TObject);
  Private
    { Private declarations }
  Public
    { Public declarations }
  End;

Var
  Form1: TForm1;

Implementation

Uses
	Unit2;

{$R *.DFM}


//-------------------------------------------------------------

Procedure TForm1.ZipTV1Read(Sender: TObject; Offset, Filenum: Integer);
Var
   ZipCommon        : TZipCommon;
   BuildString      : AnsiString;                 (* Long String *)
Begin

   (* ZipCommon is the parent class to all ZipTV components.			*)
   (* Typecast the 'Sender' parameter as type TZipCommon to share		*)
   (* properties with all components.											*)
   ZipCommon := TZipCommon( Sender );

   (* Delimiter is a property of the ZipListBox *)
   With ZipView1 Do                               (* for the Delimiter variable *)
   Begin

      BuildString :=
         ExtractFilename( ZipCommon.FileName ) + Delimiter +

      (* Date property 			*)
      FormatDateTime( 'mm' + DateSeparator + 'dd' +
      	DateSeparator + 'yy hh:mm', ZipCommon.Date ) + Delimiter +
   	// ...or...
      //DateTimeToStr(ZipCommon.Date) + Delimiter +

      IntToStr( ZipCommon.PackedSize ) + Delimiter +
      IntToStr( ZipCommon.UnpackedSize ) + Delimiter +
      IntToStr( ZipCommon.Ratio ) + '%' + Delimiter +
      ZipCommon.sCompressionMethod + Delimiter +

      //..or
      //IntToStr( ZipCommon.wCompressionMethod ) + Delimiter +

      ZipCommon.FileAttrToString( ZipCommon.ExternalAttr, Byte('_') ) +
         ' (' + IntToStr( ZipCommon.ExternalAttr ) + ')' + Delimiter +

      ExtractFilePath( ZipCommon.FileName ) + Delimiter +
      ZipCommon.GetFileType( ZipCommon.FileName ) + Delimiter +

      //IntToStr( ZipCommon.CRC ) + Delimiter +
      //..or

      IntToHex( ZipCommon.CRC, 8 ) + Delimiter +
      IntToStr( Offset ) + Delimiter;

      If ZipCommon.Encrypted Then
         BuildString := BuildString + 'Yes' + Delimiter
      Else
         BuildString := BuildString + 'No' + Delimiter;

      BuildString := BuildString + ZipCommon.VolumeName + Delimiter;

      (* FileComment is NOT included in TZipCommon (as we typecast-ed using
      Sender previously in this procedure)... only TZipTV *)
      BuildString := BuildString + StrPas( ZipCommon.FileComment );

      ZipView1.Items.Add( BuildString );
   End;
End;
//-------------------------------------------------------------

//NOTE: using ZipTV1.Activate(s: TStream32), do NOT set the
//ArchiveFile property!  Set all other properties as you
//normally would, but skip setting ArchiveFile.  The stream
//passed to the Activate method must be filled by a file
//or other memory stream prior to calling the .Activate
//method.
Procedure TForm1.Button1Click(Sender: TObject);
Var
   aFile: String;
	FileStream: TFileStream32;
   MemoryStream: TMemoryStream32;
Begin
   ZipView1.Items.BeginUpdate();
	ZipView1.Clear();

	aFile := 'c:\3\zip\iconjack.zip';
   If Not FileExists(aFile) Then
   Begin
   	ShowMessage('File not found: ' + aFile);
   	ShowMessage('Change the filename in Button1''s OnClick event');
      Exit;
   End;

	ZipTV1.FileSpec.Clear();
   ZipTV1.FileSpec.Add('*.*');

   FileStream := TFileStream32.Create(aFile, fmOpenRead Or fmShareDenyWrite );
   If (FileStream.Handle < 0) Then
   Begin
      ShowMessage('Unable to open file: ' + aFile);
      Exit;
   End;

   // just for test purposes, we'll copy the entire FileStream to
   // MemoryStream and release FileStream.  ZipTV1.Activate() is
   // called using a memory stream.
   MemoryStream := TMemoryStream32.Create();
   Try
      Try
         MemoryStream.CopyFrom(FileStream, FileStream.Size);
      Finally
         FileStream.Free();
      End;

      ZipTV1.Activate(MemoryStream);
   Finally
      MemoryStream.Free();
   End;

   ZipView1.Items.EndUpdate();
End;
//-------------------------------------------------------------

// OnError event
Procedure TForm1.ZipTV1Error(Sender: TObject; FileName, ExtendedMsg,
  VolumeID: String; ECode: Integer);
Var
   NewItem: TListItem;
Begin
   If Form2 <> Nil Then	// has form been created?
   Begin
      NewItem := Form2.ListView1.Items.Insert( 0 ); (* Create a new row *)
      With NewItem Do
      Begin
         Caption := LowerCase( Sender.ClassName );
         With SubItems Do
         Begin
            Add( LowerCase( TZipCommon( Sender ).ArchiveFile ) ); // archive FileName
            Add( LowerCase( ExtractFilename( FileName ) ) ); // FileName
            Add( IntToStr( Ecode ) );             // convert error number to a string
            Add( LoadStr( Ecode ) );              // Load error string from err_msgs.rc & err_msgs.pas
            Add( ExtendedMsg );							// Extended message such as required event params
         End;
      End;
   	Form2.ShowModal();
   End;
End;
//-------------------------------------------------------------

Procedure TForm1.mnuErrorMessages1Click(Sender: TObject);
Begin
   Form2.Show();  // Error messages form
End;
//-------------------------------------------------------------

End.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -