title: Delphi 10.2 how to use the ZipProgress
body: <p>An earlier StackOverflow topic provides some sample code for using the progress event while using <code>TZipFile</code>:</p>
  
  <p><a href="https://stackoverflow.com/questions/45383554/">Using Delphi Toyko creating a Zip file onprocess example</a></p>
  
  <p>I am able to make the example work if I use it as a MainForm. But I am completely stymied in trying to convert the code to work in a separate unit.</p>
  
  <p>Every time I try to compile the code as a unit, I get an error message:</p>
  
  <blockquote>
    <p>E2009 Incompatible types: 'method pointer and regular procedure'</p>
  </blockquote>
  
  <p>The error is triggered on the line:</p>
  
  <pre class="lang-pascal prettyprint-override"><code>TZipFile.ZipDirectoryContents('C:\temp\Test.zip','c:\temp\zipTest',zcDeflate,OnZipProgressEvent);
  </code></pre>
  
  <p>I've researched in every way I could think of, and tried all manner of alternatives, but no luck.</p>
  
  <p>Can anyone explain how to make the <code>OnZipProgressEvent</code> code work in a separate unit?</p>
  
  <p>This is the unit code that I have so far:</p>
  
  <pre class="lang-pascal prettyprint-override"><code>unit ZipDelphiNative; 
  
  interface 
  
  uses 
    Windows,SysUtils, StrUtils, Variants, MaskUtils, Dialogs,StdCtrls, 
    Graphics, Menus,Classes, ClipBrd,  System.Zip, Winapi.Messages, 
    System.Generics.Collections, system.ioutils,  system.types, 
    Forms,ComCtrls, DateUtils; 
  
  Type 
    TZipProgressEvent = procedure(Sender: TObject; FileName: string; Header: TZipHeader; Position: Int64) of object; 
    // TZipProgressEvent = procedure(Sender: TObject; FileName: string; Header: TZipHeader; Position: Int64); 
  
  function jrCreateZipFromFolder(inZipName : string; inSourcePath : string; inTargetPath : string) : boolean; 
  procedure OnZipProgressEvent (Sender: TObject; FileName: string; Header: TZipHeader; Position: Int64); 
  
  var 
    PreviousFilename : string; 
  
  implementation 
  
  uses
    Unit1; 
  
  function jrCreateZipFromFolder(inZipName : string; inSourcePath : string; inTargetPath : string) : boolean; 
    //inTargetPath is already confirmed to be valid 
    //Zips all files in inSourcePath &amp; subfolders 
  var 
    Zip : TZipFile; 
    //  ZipCallBack: TZipProgressEvent; 
    sZipName, sSourceName : string; 
  begin 
    result := true; 
    //  ZipCallBack :=  OnZipProgressEvent; 
    sZipName := IncludeTrailingBackslash(inTargetPath) + inZipName; 
    sSourceName := IncludeTrailingBackslash(inSourcePath) ; 
    Zip := TZipFile.Create; 
    try 
      if FileExists(sZipName) then 
        DeleteFile(sZipName); 
  
      //    zip.ZipDirectoryContents(sZipName, sSourceName, zcDeflate, ZipCallBack);  //do not store folder too 
  
      zip.ZipDirectoryContents(sZipName, sSourceName, zcDeflate, OnZipProgressEvent);  //do not store folder too 
  
      zip.Close; 
  
    except 
      result := false; 
    end; 
    FreeAndNil(Zip); 
  end; 
  
  procedure OnZipProgressEvent(Sender: TObject; FileName: string; 
    Header: TZipHeader; Position: Int64); 
  begin 
    if PreviousFilename &lt;&gt; FileName then 
    begin 
      PreviousFilename := FileName; 
      unit1.Form1.ProgressBar1.Max := Header.UncompressedSize; 
      unit1.Form1.ProgressBar1.Position := Position; 
    end 
    else 
      //    Unit1.Form1.ProgressBar1.Position := (Position * 100) div Header.UncompressedSize ; 
      Unit1.Form1.ProgressBar1.Position := Position; 
    Application.ProcessMessages; 
  end; 
  
  end. 
  </code></pre>
  
  <p>I have tried defining <code>TZipProgressEvent</code> with and without <code>of object</code>.  I have two options in this code for using the <code>TZipProgressEvent</code>, either like the original example, or the commented out version of defining <code>ZipCallBack</code>. Both work under different circumstances when used in a Form. Neither work when used in this unit.</p>
  
  <p>So, I am baffled as to how to make this work. It would sure be nice if Embarcadero offered useful sample code!</p>