Delphi Xe4. There is a set of components for data compression : ABBREVIA (http://tpabbrevia.sourceforge.net) It implements LZMA compression, and a module AbLZMA.pas (Lzma compression / decompression routines).
Use it :
...
Uses ablzma;
...
procedure TForm1.Button1Click(Sender: TObject);
var f1,f2:tfilestream;
begin
f1:=tfilestream.Create('d:\1.test',fmOpenRead);
f2:=tfilestream.Create('d:\1.lzma',fmCreate);
LzmaEncodeStream(f1,f2,f1.Size);
f2.Free;
f1.Free;
end;
...
Everything is working fine.
Questions:
- how to add code to display percent complete operation?
- how to add code to the abort of the compression process?
In module AbLZMA.pas (also tried to use AbLZMAStream.pas) is the main procedure LzmaEnc_Encode, who works at a call LzmaEncodeStream:
function LzmaEnc_Encode(p: CLzmaEncHandle; outStream: PISeqOutStream;
inStream: PISeqInStream; Progress: PICompressProgress;
Alloc, allocBig: PISzAlloc): SRes; cdecl; external;
It has a parameter "Progress: PICompressProgress;", where
ICompressProgress = packed record
Progress: function(p: Pointer; inSize, outSize: Int64): SRes; cdecl;
end;
PICompressProgress = ^ICompressProgress;
I tried to add a procedure in the module AbLZMA.pas:
function MyProgress(p: Pointer; inSize, outSize: Int64): SRes;cdecl;
begin
// what is "p"?
// form1.caption:=result //?
end;
...
procedure LzmaEncodeStream(ASourceStream, ATargetStream: TStream; ASourceSize: Int64);
var
...
PMyProgress:PICompressProgress;
begin
...
PMyProgress.Progress:=MyProgress;
...
LzmaCheck(LzmaEnc_Encode(LEncHandle, @LOutStreamRec.Intf, @LInStreamRec.Intf,
{nil}PMyProgress // this
,@DelphiMMInterface, @DelphiMMInterface));
...
end;
In this case (even if the body of the procedure blank), getting Error AV. How to get the data from the current percentage of completion?
form1.Caption:=inttostr(insize);
if {CANCALBUTTONCLICK} then result:=SZ_ERROR_PROGRESS;
Correct? – Gu. Sep 22 '13 at 13:50