Thank you for TRon!
I think you got the key point,but the error still exists, unit1.pas(52,41) Error: Identifier not found "ProgressCallback" .
i list the whole code below:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
windows;
type
{ TForm1 }
TForm1 = class(TForm)
edtPath: TEdit;
Memo1: TMemo;
ProgressBar1: TProgressBar;
zlib: TButton;
procedure zlibClick(Sender: TObject);
private
public
function ProgressCallback(Sender: Pointer; total: boolean; value: int64):HRESULT;stdcall;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
Uses sevenzip;
procedure TForm1.zlibClick(Sender: TObject);
var
Arch: I7zOutArchive;
Counter: Integer;
sZipFile: string;
begin
if not DirectoryExists(edtPath.Text) then
begin
ShowMessage('please select a file');
edtPath.SetFocus;
end;
Memo1.Lines.Add('start compressing');
Arch := CreateOutArchive(CLSID_CFormat7z);
Arch.SetProgressCallback(nil,@Unit1.ProgressCallback); //error line
Arch.AddFiles(edtPath.Text, '', '*.*', False);
SetCompressionLevel(Arch, 5);
SevenZipSetCompressionMethod(Arch, m7LZMA);
sZipFile := 'd:\path.7z';
Arch.SaveToFile(sZipFile);
Memo1.Lines.Append('finish compression,the file is:' + sZipFile);
//CalcZipScale(sZipFile, ProgressBar1.Max);
end;
function ProgressCallback(Sender: Pointer; total: boolean; value: int64) : HRESULT; stdcall;
begin
if total then
Form1.ProgressBar1.Max := value
else
Form1.ProgressBar1.Position := value;
Result := S_OK;
end;
end.