我们现在做个项目,里面有一个小功能,是将图片打包成一个zip文件,但是我们用dephi自带的zip插件,打的包,像winrar 和 winzip 都解压不出来,后来发现,此插件的运用,必须用dephi写自己的解压程序,比较麻烦,问:能不能 用dephi 调用什么dll之类的 来进行打zip包,不用自己带的zip插件。
  有做过的哥们给贴一下哈!

解决方案 »

  1.   

    ShellExecute(Handle,Pchar('OPEN'),pchar('WinRAR.exe'),Pchar('a d:\001.txt),nil,SW_SHOWNORMAL);
      

  2.   

    我也做好了,用VclZIP组件压缩的,可以用ZIP软件进行解压。
      

  3.   

    第一种方法,不可取,有的用户可能没有安装winRAR
      

  4.   

    逸帆 ,您做的可以用zip软件进行解压,比如 winzip 或者 winRar 吗
      

  5.   

    想 window2000,xp,20003,都有系统自己带的zip压缩程序吧,能调用api吗?
      

  6.   

    最好还是用组件的方式,不用考虑目标用户的是否有解压软件之类的,当然中有是标准的ZIP,那么winzip和winrar都能解压的。VCLZIP组件压缩的用能winzip或winrar解压。
      

  7.   

    VCLZIP 能用 Winrar 解压,我试验一下,谢谢楼上的
      

  8.   


    以前做了一个安装包.将driver.cdb的压缩包,unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ztvBase, ztvUnCab, ztvregister, ztvMakeCab;type
      TForm1 = class(TForm)
        MakeCab1: TMakeCab;
        UnCab1: TUnCab;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
    cabname,cabsource:string;
    copydir:string;
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    Var
       FilesCompressed: Integer;
    Begin
       Cursor := crHourGlass;
        If FileExists(cabname) Then
          If MessageDlg(
             'Archive exists... overwrite?',
             mtConfirmation,
             [mbYes, mbNo],
             0) = mrYes Then
             // move to recycle bin
             DeleteFile(cabname)
             //EraseFile(pchar(cabname), doAllowUndo) // EraseFile is in ztvBase.pas
          Else
             Exit;   MakeCab1.ArchiveFile := cabname;  // archive filename   MakeCab1.DateAttribute := daFileDate; // default value
       MakeCab1.StoredDirNames := sdRelative; // default value
       MakeCab1.CompressMethod := cmDeflate; // default value
       MakeCab1.RecurseDirs := false; // default = False
       MakeCab1.Switch := swAdd;            // default value
       //MakeCab1.StoreEmptySubDirs := False;     // default value
       //MakeCab1.EncryptHeaders := CheckBox1.Checked; // default = False   MakeCab1.ExcludeSpec.Clear();
       MakeCab1.FileSpec.Clear();
       MakeCab1.FileSpec.Add(cabsource);   // test with c:\windows\*.txt   // ****************************************************************
       // NOTE: for a better understanding of how the Attributes property
       // works with file attributes see demo demos\filescan\fs_demo.dpr.
       // ****************************************************************   // See the Attributes property in the object inspector
       // Set MakeCab1 Attributes property by calling the SetAttribute method
       MakeCab1.SetAttribute(fsZeroAttr, True); // default
       MakeCab1.SetAttribute(fsArchive, True); // default
       MakeCab1.SetAttribute(fsDirectory, True); // default = False
       MakeCab1.SetAttribute(fsHidden, True); // default = False
       MakeCab1.SetAttribute(fsReadOnly, True); // default
       MakeCab1.SetAttribute(fsSysFile, True); // default = False   // See the AttributesEx property in teh object inspector
       // Set the AttributesEx property by calling the SetAttributeEx method.
       // Exclude none
       MakeCab1.SetAttributeEx(fsZeroAttr, False); // default
       MakeCab1.SetAttributeEx(fsArchive, False); // default
       MakeCab1.SetAttributeEx(fsDirectory, False); // default
       MakeCab1.SetAttributeEx(fsHidden, False); // default
       MakeCab1.SetAttributeEx(fsReadOnly, False); // default
       MakeCab1.SetAttributeEx(fsSysFile, False); // default   // ***********************************
       // Call the Compress method
       // ***********************************
       FilesCompressed := MakeCab1.Compress();
       ShowMessage('Files Compressed: ' + IntToStr(FilesCompressed));   Cursor := crDefault;
    //   If frmErrorMsgs.ListView1.Items.Count > 0 Then
    //      frmErrorMsgs.ShowModal();
          
    End;procedure TForm1.Button2Click(Sender: TObject);
    Var
       FilesExtracted: Integer;
    Begin
       UnCab1.ArchiveFile := cabname;    // archive filename UnCab1.OverwriteMode := omOverwrite;
       UnCab1.ConfirmOverwrites := false; // default = False
       UnCab1.RecurseDirs := false; // default = False
       UnCab1.UseStoredDirs :=true;   UnCab1.FileSpec.Clear();             //
       UnCab1.FileSpec.Add('*.*');     // *.* = extract all
       UnCab1.ExtractDir := copydir;     //
       If DirectoryExists(copydir) Then  // if the directory exists then extract
       Begin
          FilesExtracted := UnCab1.Extract();
          ShowMessage('Files Extracted: ' + IntToStr(FilesExtracted));
       End
       Else
       Begin
          ShowMessage('Extract dir not defined');
          Exit;
       End;
    End;procedure TForm1.FormCreate(Sender: TObject);
    begin
    cabname:='c:\zdl.ca_';
    cabsource:='C:\安装包\source1\*.*' ;
    copydir:='c:\abc';
    end;end.
    下面是解压的过程.
       UnCab1.ArchiveFile := extractfilepath(paramstr(0))+'\driver.cbd';    // archive filename UnCab1.OverwriteMode := omOverwrite;
       UnCab1.ConfirmOverwrites := false; // default = False
       UnCab1.RecurseDirs := false; // default = False
       UnCab1.UseStoredDirs :=true;   UnCab1.FileSpec.Clear();             //
       UnCab1.FileSpec.Add('*.*');     // *.* = extract all
       UnCab1.ExtractDir := edit1.Text;     //
       If DirectoryExists(edit1.Text) Then  FilesExtracted:= UnCab1.Extract()   Else
       Begin
          ShowMessage('解压目录不存在');
          Exit;
       End;
    刚踏上CSDN,多给点分吧.