7z在Delphi 2007中

Ciu*_*caS 0 delphi 7zip delphi-2007 jedi

我正在尝试使用Delphi 2007使用JEDI JCL压缩一些文件.问题是我无法弄清楚为什么我一直得到这个错误" Sevenzip: Failed to load 7z.dll"

我的代码是:

var
   archiveclass: TJclDecompressArchiveClass;
   archive: TJclDecompressArchive;
   item: TJclCompressionItem;
   s: String;
   i: Integer;
begin
   archiveclass := GetArchiveFormats.FindDecompressFormat(dir);

   if not Assigned(archiveclass) then
      raise Exception.Create('Could not determine the Format of ' + dir);

   archive := archiveclass.Create(dir);
   try
      if not (archive is TJclSevenZipDecompressArchive) then
         raise Exception.Create('This format is not handled by 7z.dll');

      archive.ListFiles;

      s := Format('test.zip Item Count: %d'#13#10#13#10, [archive.ItemCount]);

      for i := 0 to archive.ItemCount - 1 do
      begin
         item := archive.Items[i];
         case item.Kind of
            ikFile:
               s := s + IntToStr(i+1) + ': ' + item.PackedName + #13#10;
            ikDirectory:
               s := s + IntToStr(i+1) + ': ' + item.PackedName + '\'#13#10;//'
         end;
      end;

      if archive.ItemCount > 0 then
      begin
//         archive.Items[0].Selected := true;
//         archive.ExtractSelected('F:\temp\test');

         archive.ExtractAll('F:\temp\test');
      end;

      ShowMessage(s);
   finally
      archive.Free;
   end;
Run Code Online (Sandbox Code Playgroud)

我在与Delphi项目相同的文件夹中有7z.dll.我究竟做错了什么?7z文件夹还有其他简单的方法吗?我不是在寻找一些复杂的任务,只是为了从文件夹创建一个zip.

Del*_*ics 5

JCLCompression单元仅将7z API包装在JCLCompression类中.7z API本身驻留在SevenZip.pas单元中(在JCL源的windows文件夹中).这是加载7z.dll的地方(需要时通过Load7Zip例程).

您似乎正在使用动态链接到该DLL来编译项目,导致DLL仅在需要时加载,而不是加载并与您的EXE链接.加载失败以及您在异常中看到的错误消息表明在运行时查找或加载该DLL存在一些问题.

要检查的事项:

  • 确保7z.dll 与EXE位于同一文件夹中(不是 DPR源文件,而是运行时的EXE)

  • 确保您使用的7z.dll 是32位. Delphi 2007仅生成32位可执行文件,因此即使在64位操作系统上,您仍然需要32位版本的7z.dll用于Delphi应用程序.