Contents - Index - Previous - Next


OnStartZip event

 

Applies to

TVCLZip component

 

Declaration

property OnStartZip: TStartZipEvent = procedure(Sender: TObject; FName: string; var ZipHeader: TZipHeaderInfo; var Skip: Boolean); of object;

 

Description

The OnStartZip event handler is executed when a file is about to be compressed.  This gives you a chance to convey information to the user, skip this particular file, or even modify some of the information that is stored along with it in the archive.  

 

IMPORTANT: Be sure to include kpZipObj in your USES list if you plan on using this event!  It has the required definition of the ZipHeaderInfo object. 

 

Parameters  

FName: The filename of the file about to be compressed including the full path. 

 

Skip:  Set this to True if you do not wish to compress this file.  This is useful if you want to avoid zipping certain files. Say for instance you don't want to zip files with the extention '.TMP'.  You could check FName to see if it's extention is '.TMP' and if so, set Skip to True.  No '.TMP' files will be zipped. 

 

ZipHeader: This object contains all of the information for this file that will go into the archive.  You may change this information but you must be careful because you could corrupt the archive if you try to do things that you shouldn't. If you stick to changing only the following information you will be safe:  

 

ZipHeader.Filename Change this file's Filename (in the archive)  

ZipHeader.Pathname Change this file's path information  

ZipHeader.SetDateTime( DateTime: TDateTime ) Change the timestamp for this file  

ZipHeader.SetNewFileComment( NewComment: String ) Add a comment for this file 

 

For example in your OnStartZip event you may wish to do something like the following: 

 

procedure MyForm.OnStartZip( Sender: TObject; FName: String;  var ZipHeader: TZipHeaderInfo; var Skip: Boolean ); 

begin 

If UpperCase(ExtractFileExt(FName)) = '.DLL' then /* Do only to DLL files*/ 

begin 

ChangeFileExt( Zipper.filename, '.DL_'); /* Change the extention*/ 

ZipHeader.SetDateTime( Now ); /* Set the time to current time */ 

ZipHeader.Pathname := 'DEFAULT\DLL'; /*  DLL's go into the DLL dir*/ 

ZipHeader.SetNewFileComment( 'This is a DLL' ); /* Create a comment for DLL's*/ 

end; 

end;