I use Delphi TZipMaster to create and extract ZIP files. It works but the problem is , when something goes wrong, it won't generate an exception, it will show a message from the component itself.
So in the code below :
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;
I don't think you need to go about doing what you want by catching exceptions.
The TZipMaster component has an OnMessage
event - see here for documenttation http://www.delphizip.org/192/help/index.html - which you can use to detect the error condition you mention and then take action as necessary, e.g. by calling the TZipMaster's Cancel
method.
The current error code is passed to the OnMessage
event. The invalid archive message's errcode value is ZE_NoValidZip, so when that code is passed to OnMessage
, so that could be when you react by calling Cancel
.