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

📄 unit1.pas

📁 ziptv为delphi控件
💻 PAS
字号:
Unit Unit1;

Interface

Uses
   Windows,
   Messages,
   SysUtils,
   Classes,
   Graphics,
   Controls,
   Forms,
   Dialogs,
   StdCtrls,
   ExtCtrls,
   Buttons,
   ComCtrls,
   CommCtrl,

   ztvRegister,
   ztvBase,
   ztvGbls,
   ztvConsts,
   ztvArchiveEditor,
   Err_Msgs,
   ztvZipCheck;

Type
   TForm1 = Class(TForm)
      Edit1: TEdit;
      Panel1: TPanel;
      Label1: TLabel;
      BitBtn1: TBitBtn;
      OpenDialog1: TOpenDialog;
      ArchiveEditor1: TArchiveEditor;
      Panel6: TPanel;
      Panel3: TPanel;
      GroupBox1: TGroupBox;
      cbReadOnly: TCheckBox;
      cbSysFile: TCheckBox;
      cbDirectory: TCheckBox;
      cbArchive: TCheckBox;
      cbHidden: TCheckBox;
      cbVolumeID: TCheckBox;
      cbZeroAttr: TCheckBox;
      cbEncrypted: TCheckBox;
      Panel5: TPanel;
      Panel2: TPanel;
      ListBox1: TListBox;
      Panel4: TPanel;
      Label2: TLabel;
      Label4: TLabel;
      Label5: TLabel;
      Edit3: TEdit;
      DateTimePicker2: TDateTimePicker;
      DateTimePicker1: TDateTimePicker;
      Button1: TButton;
      Button3: TButton;
      Memo1: TMemo;
      Button2: TButton;
      Button4: TButton;
      Procedure ArchiveEditor1Error(Sender: TObject; FileName, ExtendedMsg,
         VolumeID: String; ECode: Integer);
      Procedure ArchiveEditor1GetCompressedFileName(Sender: TObject; FileName: String);
      Procedure Button1Click(Sender: TObject);
      Procedure Button2Click(Sender: TObject);
      Procedure Button3Click(Sender: TObject);
      Procedure Button4Click(Sender: TObject);
      Procedure BitBtn1Click(Sender: TObject);
      Procedure cbFileAttrCommonClick(Sender: TObject);
      Procedure DateTimePicker1CloseUp(Sender: TObject);
      Procedure DateTimePicker2Change(Sender: TObject);
      Procedure Edit1KeyPress(Sender: TObject; Var Key: Char);
      Procedure Edit3Change(Sender: TObject);
      Procedure FormClose(Sender: TObject; Var Action: TCloseAction);
      Procedure ListBox1Click(Sender: TObject);
      Procedure FormActivate(Sender: TObject);
   Private
      { Private declarations }
   Public
      CurrentItemIndex: Integer;
      Procedure EnableButtons;
   End;

Var
   Form1: TForm1;

   {$I ziptv.inc}                       // include ziptv preset compiler switches

Implementation

Uses Unit2;

Const
   // Setting a CheckBox's checked property in code, will activate that
     // CheckBox's click event.  The following variable is used to bypass the
     // execution of the code in the cbFileAttrCommonClick event when these
     // CheckBox's checked properties are set in code, while still allowing the
     // execution of the code in cbFileAttrCommonClick when the CheckBox is
     // manually clicked.
   BypassClick: Boolean = False;

   {$R *.DFM}

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

Procedure TForm1.ArchiveEditor1Error(Sender: TObject; FileName, ExtendedMsg,
   VolumeID: String; ECode: Integer);
Var
   ShowStr: String;
Begin
   ShowStr :=
      LowerCase(Sender.Classname) + #13 +
      LowerCase(TZipCommon(Sender).ArchiveFile) + #13 +
      LowerCase(ExtractFilename(FileName)) + #13 +
      IntToStr(ECode) + #13 +
      LoadStr(ECode) + #13 +
      ExtendedMsg;

   ShowMessage(ShowStr);
End;
//------------------------------------------------------------

Procedure TForm1.Button1Click(Sender: TObject);
Begin
   If ArchiveEditor1.RestoreRecord(ListBox1.ItemIndex) Then
      ListBox1Click(Sender);

   EnableButtons();
End;
//------------------------------------------------------------

Procedure TForm1.Button3Click(Sender: TObject);
Var
   Key: Char;
Begin
   If MessageDlg('Commit updates?', mtConfirmation, [mbYes, mbNo], 0) = mrYes Then
   Begin
      ArchiveEditor1.CommitUpdates();

      // simulate a keypress of the enter key
      Key := #13;
      Edit1KeyPress(Sender, Key);

      EnableButtons();
   End;
End;
//------------------------------------------------------------

Procedure TForm1.FormClose(Sender: TObject; Var Action: TCloseAction);
Begin
   If ArchiveEditor1.inEditMode Then
      If ArchiveEditor1.ArchiveChanged() Then
      Begin
         If MessageDlg('Commit updates?', mtConfirmation, [mbYes, mbNo], 0) = mrYes Then
            ArchiveEditor1.CommitUpdates()
         Else
            ArchiveEditor1.RollBack();
      End
      Else
         ArchiveEditor1.RollBack();
End;
//------------------------------------------------------------

Procedure TForm1.BitBtn1Click(Sender: TObject);
Begin
   ListBox1.Clear();

   OpenDialog1.InitialDir := ExtractFileDir(Edit1.Text);
   //OpenDialog1.FileName :=
   OpenDialog1.Filter := LoadStr(F_TZIPTV);
   OpenDialog1.Title := 'Select archive to edit...';
   OpenDialog1.Options := [ofHideReadOnly, ofFileMustExist, ofPathMustExist];
   If OpenDialog1.Execute() Then
   Begin
      If MessageDlg('Have you backed up this archive?', mtConfirmation,
         [mbYes, mbNo], 0) = mrNo Then
      Begin
         ShowMessage('Create a back-up copy of the archive and try again');
         Exit;
      End;

      DateTime_SetFormat(DateTimePicker1.Handle, 'MM/dd/yyyy');
      DateTime_SetFormat(DateTimePicker2.Handle, 'hh:mm:ss tt');
      Edit1.Text := OpenDialog1.FileName;
      ArchiveEditor1.ArchiveFile := OpenDialog1.FileName;
      GroupBox1.Visible := Not (ArchiveEditor1.ArcType = atTar);
      ArchiveEditor1.StartEdit();
      If ListBox1.Items.Count > 0 Then
      Begin
         ListBox1.ItemIndex := 0;
         ListBox1Click(Sender);
      End
      Else
         Edit3.Text := '';
   End
   Else
   Begin
      FormActivate(Sender);             // blank the datetimepicker controls
      Edit1.Text := '';
   End;
End;
//------------------------------------------------------------

// OnGetCompressedFileName event.  Fill the ListBox with filenames.  This
// event is activated once for each compressed file in an archive.  It begins
// with a call to the StartEdit method.

Procedure TForm1.ArchiveEditor1GetCompressedFileName(Sender: TObject;
   FileName: String);
Begin
   ListBox1.Items.Add(FileName);
End;
//------------------------------------------------------------

// This event is simply to update the form's visual controls to coincide
// with a specific compressed file's data: file's name (edit3), attribute
// (cb checkboxes), date (DateTimePicker1), and time (DateTimePicker2).

// See the following events in this demo for examples of revising
// these properties:
// Edit3Change(..)                //revise names
// cbFileAttrCommonClick(..)      //revise attributes
// DateTimePicker1CloseUp(..)     //revise date
// DateTimePicker2Change(..)      //revise time


// 1. variables listed below beginning with "cb" are the CheckBox control
// on the form.
// 2. the captions appearing on these CheckBox controls are representative
// of the set member names in ZipTV with regard to the Attributes &
// AttributesEx properties.

Procedure TForm1.ListBox1Click(Sender: TObject);
Var
   Index: Integer;
   _FileAttr: Integer;
   _FileDate: TDateTime;
Begin
	Index := ListBox1.ItemIndex;

   // ---------------------------------------------------------------------
   // the FileName[] property is an array of strings which contains all
   // compressed filenames within the archive.  Use the ListBox1's itemindex
   // to retrieve the stored name for this index.
   Edit3.Text := ArchiveEditor1.FileName[Index];
   // ---------------------------------------------------------------------

   // ---------------------------------------------------------------------
   // the FileAttr[] property is an array of integers containing all
   // compressed file attributes within the archive.  Use the ListBox1's
   // itemindex to retrieve the stored attribute for this index.
   _FileAttr := ArchiveEditor1.FileAttr[Index];
   // ---------------------------------------------------------------------

   If (_FileAttr And SysUtils.faVolumeID > 0) Or (_FileAttr And FILE_ATTRIBUTE_DIRECTORY
      > 0) Then
      cbSysFile.Enabled := False
   Else
      cbSysFile.Enabled := True;

   BypassClick := True;

   cbZeroAttr.Checked := _FileAttr = 0;
   cbArchive.Checked := _FileAttr And ZTV_FILE_ATTRIBUTE_ARCHIVE > 0;
   cbReadOnly.Checked := _FileAttr And ZTV_FILE_ATTRIBUTE_READONLY > 0;
   cbHidden.Checked := _FileAttr And ZTV_FILE_ATTRIBUTE_HIDDEN > 0;
   cbVolumeID.Checked := _FileAttr And SysUtils.faVolumeID > 0;
   cbSysFile.Checked := _FileAttr And ZTV_FILE_ATTRIBUTE_SYSTEM > 0;
   cbDirectory.Checked := _FileAttr And ZTV_FILE_ATTRIBUTE_DIRECTORY > 0;
   cbEncrypted.Checked := _FileAttr And ZTV_FILE_ATTRIBUTE_ENCRYPTED > 0;

   BypassClick := False;

   // ---------------------------------------------------------------------
   // the FileDate[] property is an array of integers containing all
   // compressed file dates within the archive.  Use the ListBox1's
   // itemindex to retrieve the stored date for this index.
   _FileDate := ArchiveEditor1.FileDateTime[ListBox1.ItemIndex];
   // ---------------------------------------------------------------------

   //edtDate.Text := DateTimeToStr(_FileDate);

   // ------ DATE
   DateTimePicker1.DateTime := _FileDate;    // Date
   DateTimePicker1.MinDate := 29221.958333;  // Minimum date for DateTimePicker is is 1/1/1980

   // ------ TIME
   DateTimePicker2.DateTime := _FileDate;    // Time
   DateTimePicker2.MinDate := 29221.958333;  // Minimum date for DateTimePicker is is 1/1/1980
End;
//------------------------------------------------------------

// 1. set the ArchiveFile property
// 2. initialize the edit of this archive by calling the StartEdit method

Procedure TForm1.Edit1KeyPress(Sender: TObject; Var Key: Char);
Begin
   If (Key = #13) And FileExists(Edit1.Text) Then
   Begin
      ListBox1.Clear();
      DateTime_SetFormat(DateTimePicker1.Handle, 'MM/dd/yyyy');
      DateTime_SetFormat(DateTimePicker2.Handle, 'hh:mm:ss tt');
      ArchiveEditor1.ArchiveFile := Edit1.Text;
      GroupBox1.Visible := Not (ArchiveEditor1.ArcType = atTar);
      ArchiveEditor1.StartEdit();

      If ListBox1.Items.Count > 0 Then
      Begin
         ListBox1.ItemIndex := 0;
         //ListBox1.Selected[0] := True;
         ListBox1Click(Sender);
         ListBox1.SetFocus();
      End
      Else
         Edit3.Text := '';

   End;
End;
//------------------------------------------------------------

Procedure TForm1.cbFileAttrCommonClick(Sender: TObject);
Begin

   // The SetAttribute method sets the ArchiveEditor's "Attributes property".
   // Assign the FileAttrs[] property he value of this altered Attributes
   // property.
   If Not BypassClick Then
   Begin
      With ArchiveEditor1 Do
      Begin
         If ArcType = atTar Then
            ShowMessage('Unable to revise file attributes in Unix .tar file');

         If cbDirectory.Checked Then
            Exit;

         Attributes := [];
         If cbZeroAttr.Checked Then
         Begin
            SetAttribute(fsZeroAttr, cbZeroAttr.Checked);

            // if attribute is zero, no other attributes can
              // can be combined with the zero value
            BypassClick := True;
            Try
               cbArchive.Checked := False;
               cbReadOnly.Checked := False;
               cbHidden.Checked := False;
               cbSysFile.Checked := False;
               cbVolumeID.Checked := False;
               cbDirectory.Checked := False;
            Finally
               BypassClick := False;
            End;
         End
         Else
         Begin
            cbZeroAttr.Checked := False;

            // process all other attributes
            SetAttribute(fsArchive, cbArchive.Checked);
            SetAttribute(fsReadOnly, cbReadOnly.Checked);
            SetAttribute(fsHidden, cbHidden.Checked);
            SetAttribute(fsSysFile, cbSysFile.Checked);
            SetAttribute(fsVolumeID, cbVolumeID.Checked);
            SetAttribute(fsDirectory, cbDirectory.Checked);
         End;

      End;
      ArchiveEditor1.FileAttrs[ListBox1.ItemIndex] := ArchiveEditor1.Attributes;
      EnableButtons();
   End;
End;
//------------------------------------------------------------

Procedure TForm1.DateTimePicker1CloseUp(Sender: TObject);
Begin
   ArchiveEditor1.FileDateTime[ListBox1.ItemIndex] := DateTimePicker1.DateTime;
   EnableButtons();
End;
//------------------------------------------------------------

Procedure TForm1.DateTimePicker2Change(Sender: TObject);
Begin
   ArchiveEditor1.FileDateTime[ListBox1.ItemIndex] := DateTimePicker2.DateTime;
   EnableButtons();
End;
//------------------------------------------------------------

Procedure TForm1.Edit3Change(Sender: TObject);
Begin
   //If ArchiveEditor1.isInitialized And (Edit3.Text <> '') Then
   If Edit3.Text <> '' Then
   Begin
      ArchiveEditor1.FileName[ListBox1.ItemIndex] := Edit3.Text;
      ListBox1.Items[ListBox1.ItemIndex] := Edit3.Text;
      EnableButtons();
   End;
End;
//------------------------------------------------------------

Procedure TForm1.Button2Click(Sender: TObject);
Var
   i: Integer;
Begin
   For i := 0 To ArchiveEditor1.GetFileCount - 1 Do
      If ArchiveEditor1.RestoreRecord(i) Then
      Begin
         ListBox1.ItemIndex := i;
         ListBox1Click(Sender);
      End;

   EnableButtons();
End;
//------------------------------------------------------------

Procedure TForm1.Button4Click(Sender: TObject);
Begin
   frmTestArchive.ShowModal();
End;
//------------------------------------------------------------

Procedure TForm1.EnableButtons;
Begin
   Button1.Enabled := ArchiveEditor1.RecordChanged[ListBox1.ItemIndex];
   Button2.Enabled := ArchiveEditor1.ArchiveChanged();
   Button3.Enabled := Button2.Enabled;
End;
//------------------------------------------------------------
// blank the datetime picker controls

Procedure TForm1.FormActivate(Sender: TObject);
Begin
   DateTime_SetFormat(DateTimePicker1.Handle, 'gg');
   DateTime_SetFormat(DateTimePicker2.Handle, 'gg');
End;
//------------------------------------------------------------

End.

⌨️ 快捷键说明

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