【发布时间】:2013-09-22 13:31:45
【问题描述】:
德尔福 Xe4。有一组数据压缩组件:ABBREVIA (http://tpabbrevia.sourceforge.net) 它实现了 LZMA 压缩,以及一个模块 AbLZMA.pas(Lzma 压缩/解压缩例程)。
使用它:
...
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;
...
一切正常。
问题:
- 如何添加代码以显示操作完成百分比?
- 如何添加代码中止压缩过程?
在模块 AbLZMA.pas 中(也尝试使用 AbLZMAStream.pas) 是LzmaEnc_Encode的主程序,工作在调用LzmaEncodeStream:
function LzmaEnc_Encode(p: CLzmaEncHandle; outStream: PISeqOutStream;
inStream: PISeqInStream; Progress: PICompressProgress;
Alloc, allocBig: PISzAlloc): SRes; cdecl; external;
它有一个参数“Progress: PICompressProgress;”,其中
ICompressProgress = packed record
Progress: function(p: Pointer; inSize, outSize: Int64): SRes; cdecl;
end;
PICompressProgress = ^ICompressProgress;
我尝试在模块 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;
在这种情况下(即使过程的主体为空白),会出现错误 AV。如何获取当前完成百分比的数据?
【问题讨论】:
标签: delphi turbopower abbrevia