?? bzlibdemo2_mainfrm.pas
字號:
unit bzlibDemo2_MainFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AppEvnts;
type
TbzlibDemo_MainForm = class(TForm)
WriteBtn: TButton;
LogMemo: TMemo;
ApplicationEvents1: TApplicationEvents;
ReadBtn: TButton;
procedure WriteBtnClick(Sender: TObject);
procedure ApplicationEvents1Exception(Sender: TObject; E: Exception);
procedure ReadBtnClick(Sender: TObject);
private
{ Private declarations }
public
procedure WriteLn(S: string);
end;
var
bzlibDemo_MainForm: TbzlibDemo_MainForm;
implementation
{$R *.dfm}
uses
xrtl_io_FileStream,
xrtl_io_ProcessingStream, xrtl_io_bzlib_StreamProcessor;
const
DataLength = 20000000;
FName = 'c:\temp\bzlibTest';
{ TbzlibDemo_MainForm }
procedure TbzlibDemo_MainForm.WriteLn(S: string);
begin
LogMemo.Lines.Add(S);
Application.ProcessMessages;
end;
procedure TbzlibDemo_MainForm.ApplicationEvents1Exception(Sender: TObject;
E: Exception);
begin
WriteLn(Format('Exception %s: %s', [E.ClassName, E.Message]));
end;
procedure TbzlibDemo_MainForm.WriteBtnClick(Sender: TObject);
var
POS2: TXRTLProcessingOutputStream;
ZSP2: TXRTLbzlibStreamProcessor;
PIS2: TXRTLProcessingInputStream;
I: Integer;
begin
POS2:= nil;
PIS2:= nil;
try
WriteLn('Creating TXRTLProcessingOutputStream');
ZSP2:= TXRTLbzlibStreamProcessor.Create;
POS2:= TXRTLProcessingOutputStream.Create(TXRTLFileOutputStream.Create(FName, False), ZSP2, True, False);
ZSP2.InitCompress;
WriteLn('Writing data');
for I:= 0 to DataLength - 1 do
begin
POS2.WriteBuffer(I, SizeOf(I));
end;
WriteLn('Data written, closing stream');
POS2.Close;
finally
FreeAndNil(PIS2);
FreeAndNil(POS2);
end;
end;
procedure TbzlibDemo_MainForm.ReadBtnClick(Sender: TObject);
var
POS2: TXRTLProcessingOutputStream;
ZSP2: TXRTLbzlibStreamProcessor;
PIS2: TXRTLProcessingInputStream;
I, RData, Data: Integer;
begin
POS2:= nil;
PIS2:= nil;
try
WriteLn('Creating TXRTLProcessingInputStream');
ZSP2:= TXRTLbzlibStreamProcessor.Create;
PIS2:= TXRTLProcessingInputStream.Create(TXRTLFileInputStream.Create(FName, False), ZSP2, True, False);
ZSP2.InitDecompress;
WriteLn('Reading data');
I:= -1;
repeat
Inc(I);
Data:= PIS2.ReadBuffer(RData, SizeOf(RData));
if (Data > 0) and (RData <> I) then
WriteLn(Format('Data = %8.x, RData = %8.x', [I, RData]));
until Data < 0;
if I <> DataLength then
WriteLn(Format('Data = %8.x, DataLength = %8.x', [I, DataLength]));
WriteLn('Data read, closing stream');
PIS2.Close;
finally
FreeAndNil(PIS2);
FreeAndNil(POS2);
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -