This example demonstrates how to test the integrity of the files contained within the the zip file "c:\Test\zip.zip".
The first function of the following code starts the test. For this example, nothing is specified in the FilesToProcess property, so all files inside the zip file will be tested. In this example we call TestZipFile with the bCheckCompressedData parameter set to True, so that the actual compressed data is checked too, not just the zip file's structure and file headers. The second function below is a handler written for the TestingFile event that displays (in a listbox) the filename of each file being tested, along with some other of the file's information. The third function below is a handler written for the Warning event, that adds detailed information about any encountered errors into the same listbox. The code assumes you have placed a button, a listbox and an Xceed Zip control on a form, and named them Button1, ListBox1 and XceedZip1 respectively.
We start with the handler for the button's click event. The code will start the testing.
Delphi |
Copy Code |
procedure TForm1.Button1Click(Sender: TObject);
var
ResultCode : xcderror;
begin XceedZip1.License( 'your license key' );
{ Name and path of the zip file to test } Xceedzip1.zipfilename := 'c:\Test\zip.zip';
{ Start testing the file (we use True here so that we also test the actual compressed data, not just the zip file's structure }
ResultCode := Xceedzip1.TestZipFile(True);
{Check the return value}
If ResultCode <> xerSuccess Then ShowMessage('Unsuccessful. Error # ' + IntToStr(ResultCode)) Else ShowMessage('The tested zip file is completely error-free.'); end; |
Here's the handler for the TestingFile event. It will add each file's name and info to the listbox.
Delphi |
Copy Code |
procedure TForm1.XceedZip1TestingFile(Sender: TObject; const sFilename, sComment: WideString; lSize, lCompressedSize: Integer; nCompressionRatio: Smallint; xAttributes: TOleEnum; lCRC: Integer; dtLastModified, dtLastAccessed, dtCreated: TDateTime; xMethod: TOleEnum; bEncrypted: WordBool; lDiskNumber: Integer);
begin ListBox1.Items.Add ('Now testing file : ' + sFilename); ListBox1.items.Add (' Uncompressed Size : ' + IntToStr(lsize)); ListBox1.items.Add (' Compressed Size : ' + IntToStr(lcompressedsize)); ListBox1.items.Add (' Compression Ratio : ' + IntToStr(nCompressionRatio)); ListBox1.items.Add (''); end; |
Here's the handler for the Warning event. It adds information about encountered errors to the listbox.
Delphi |
Copy Code |
procedure TForm1.XceedZip1Warning(Sender: TObject;
const sFilename: WideString; xWarning: TOleEnum);
begin ShowMessage('Warning #'+ IntToStr(xWarning) + ' for file "' + sFilename + '"'); end; |