[英]7z in Delphi 2007
我正在尝试使用JEDI JCL使用Delphi 2007压缩某些文件。 问题是我不知道为什么我总是收到此错误“ 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;
我在与Delphi项目相同的文件夹中有7z.dll。 我究竟做错了什么? 还有7z文件夹的任何其他简单方法吗? 我不是在寻找一些复杂的任务,只是从文件夹创建一个zip。
JCLCompression单元仅将7z API包装在JCLCompression类内。 7z API本身位于SevenZip.pas单元中(位于JCL源的Windows文件夹中)。 这是7z.dll(在需要时通过Load7Zip例程加载)的位置。
您似乎正在通过动态链接到该DLL来编译项目,导致仅在需要时才加载DLL,而不是与EXE一起加载并链接该DLL。 加载失败以及您在异常中看到的错误消息的事实表明在运行时查找或加载该DLL存在一些问题。
检查事项:
确保7z.dll 与EXE位于同一文件夹 ( 不是 DPR源文件,而是运行时的EXE)
确保您使用的7z.dll 是32位的 。 Delphi 2007仅生成32位可执行文件,因此即使在64位OS上,对于Delphi应用程序,仍将需要32位版本的7z.dll 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.