使用Delphi的7-Zip吗?
时间:2020-03-05 18:56:32 来源:igfitidea点击:
我想使用Delphi的7-Zip DLL,但找不到合适的文档或者示例。有谁知道如何使用Delphi的7-Zip DLL?
解决方案
回答
从1.102版开始,JEDI代码库支持JclCompression单元内置的7-Zip。不过,我自己还没有使用过它。
回答
如果仅打算将7Zip用于zip和unzip,请看一下TZip组件。
我已经为自己的目的编写了一个小型包装器,我们可以在Zipper.pas文件中找到该包装器,可以随时重复使用。
回答
像许多JEDI代码库一样,扩展了Oliver Giesen的答案,我找不到任何合适的文档,但这对我有用:
uses JclCompression; procedure TfrmSevenZipTest.Button1Click(Sender: TObject); const FILENAME = 'F:\temp\test.zip'; var archiveclass: TJclDecompressArchiveClass; archive: TJclDecompressArchive; item: TJclCompressionItem; s: String; i: Integer; begin archiveclass := GetArchiveFormats.FindDecompressFormat(FILENAME); if not Assigned(archiveclass) then raise Exception.Create('Could not determine the Format of ' + FILENAME); archive := archiveclass.Create(FILENAME); 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; end;
回答
7 Zip插件API
http://www.progdigy.com/?page_id=13