Delphi TZipMaster - 如何捕获异常?

问题描述 投票:0回答:1

我使用Delphi TZipMaster来创建和提取ZIP文件。它的工作原理但问题是,当出现问题时,它不会产生异常,它会显示来自组件本身的消息。

所以在下面的代码中:

try
zipmaster1.ZipFileName := 'C:\example.zip';
zipmaster1.FSpecArgs.Clear;
zipmaster1.fspecargs.Add('installl.exe');
zipmaster1.ExtrBaseDir := 'c:\';
// the line below will show a message 'This archive is not a valid ZIP archive';
// i want it to throw an exception instead, so i can catch it and handle in my app
zipmaster1.Extract; 
except
// never will reach here
end;
delphi delphi-2007
1个回答
2
投票

我不认为您需要通过捕获异常来做您想做的事情。

TZipMaster组件有一个OnMessage事件 - 请参阅此处的文档http://www.delphizip.org/192/help/index.html - 您可以使用它来检测您提到的错误情况,然后根据需要采取措施,例如:通过调用TZipMaster的Cancel方法。

当前错误代码将传递给OnMessage事件。无效的存档消息的错误代码值是ZE_NoValidZip,因此当该代码传递给OnMessage时,可能是在您通过调用Cancel做出反应时。

© www.soinside.com 2019 - 2024. All rights reserved.