为什么我用ZLIB解压缩的文件无法打开呢?我的代码如下:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,zlib, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
count: integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
SourceStream:Tfilestream;
DestStream:TfileStream;
CompressStream:TCompressionStream;
begin
if opendialog1.Execute then
begin
SourceStream:=TFilestream.Create(opendialog1.FileName,fmopenread);
DestStream:=TFileStream.Create (opendialog1.FileName+'.cse',fmCreate);
CompressStream:=TCompressionStream.Create(clmax,DestStream);
compressStream.CopyFrom(SourceStream,SourceStream.Size);
count:=SourceStream.Size;
end;
SourceStream.Free;
DestStream.Free;
end;procedure TForm1.Button2Click(Sender: TObject);
var
SourceStream:Tfilestream;
DestStream:TfileStream;
CompressStream:TDeCompressionStream;
buffer:pointer;
//Buffer: array of Char;begin
if opendialog1.Execute then
SourceStream:=TFilestream.Create(opendialog1.FileName,fmopenread);
if savedialog1.Execute then
DestStream:=TFileStream.Create (Savedialog1.FileName ,fmCreate);
CompressStream:=TDeCompressionStream.Create(SourceStream);
//setlength(buffer,count);
getmem(buffer,SourceStream);
CompressStream.Read(buffer^,count+1);
DestStream.Write(buffer^,count+1);
freemem(buffer,count+1);
SourceStream.Free;
DestStream.Free;
end;end.
不知道错在哪里请高手指点,谢谢!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,zlib, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
count: integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
SourceStream:Tfilestream;
DestStream:TfileStream;
CompressStream:TCompressionStream;
begin
if opendialog1.Execute then
begin
SourceStream:=TFilestream.Create(opendialog1.FileName,fmopenread);
DestStream:=TFileStream.Create (opendialog1.FileName+'.cse',fmCreate);
CompressStream:=TCompressionStream.Create(clmax,DestStream);
compressStream.CopyFrom(SourceStream,SourceStream.Size);
count:=SourceStream.Size;
end;
SourceStream.Free;
DestStream.Free;
end;procedure TForm1.Button2Click(Sender: TObject);
var
SourceStream:Tfilestream;
DestStream:TfileStream;
CompressStream:TDeCompressionStream;
buffer:pointer;
//Buffer: array of Char;begin
if opendialog1.Execute then
SourceStream:=TFilestream.Create(opendialog1.FileName,fmopenread);
if savedialog1.Execute then
DestStream:=TFileStream.Create (Savedialog1.FileName ,fmCreate);
CompressStream:=TDeCompressionStream.Create(SourceStream);
//setlength(buffer,count);
getmem(buffer,SourceStream);
CompressStream.Read(buffer^,count+1);
DestStream.Write(buffer^,count+1);
freemem(buffer,count+1);
SourceStream.Free;
DestStream.Free;
end;end.
不知道错在哪里请高手指点,谢谢!
改成
getmem(buffer,count);