从此不再编程!太难了。(27分)

L

lah998

Unregistered / Unconfirmed
GUEST, unregistred user!
我把一个文件夹下的三个文件压缩成一个文件,然后逐个来解压,解第一个文件时就不行了
,是空的,只有一个文件名没有东西(假设是文本文件)。如果大富翁的朋友们都帮不了我,
我只有放弃编程。叹息:做人难,做女人更难!

procedure DecompressStream(inpStream, outStream: TStream);//解压过程
var
InpBuf, OutBuf: Pointer

OutBytes, sz: Integer

begin
InpBuf := nil

OutBuf := nil

sz := inpStream.Size - inpStream.Position

if sz > 0 then
try
GetMem(InpBuf, sz)

inpStream.Read(InpBuf^, sz)

DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes)

outStream.Write(OutBuf^, OutBytes)

finally
if InpBuf <> nil then FreeMem(InpBuf)

if OutBuf <> nil then FreeMem(OutBuf)

end

outStream.Position := 0

end


procedure TForm1.Button3Click(Sender: TObject);
var
Ms,MyMsFile,Fs:TMemoryStream;
MyFile:string;
MyInt:integer;
begin
Ms:=TMemoryStream.Create ;
MyMsFile:=TMemoryStream.Create ;
Fs:=TMemoryStream.Create ;
try

Ms.LoadFromFile('c:/123.jmi');//是我压缩后的文件假设里面含有三个文件,把它打开
...
Ms.Position :=0;
Fs.CopyFrom(Ms,MyInt)//假设第一个文件大小是MyInt.
DecompressStream(Fs,MyMs);//解压第一个文件
MyMs.SaveToFile(MyFile);//保存第一个文件(为什么这个文件是空的!!!)
FINALLY
Ms.Free;
MyMsFile.Free ;
Fs.Free;
end;
end;
 
把你的程序全贴出来吧
这样比较好查错
 
your age is 27[:)][:)]
 
王公子:仅有的27分!
 
form1.,:够多了啊
 
没出息。

把你完整的压缩解压贴出来。
 
jsxjd:没有东西贴啦!这是D6自带的压缩啊,只要Uses zLib就可以了
 
呵呵..
放弃吧
 
试试我的代码(Uses ZLib)--
procedure CompressFile(InFile, OutFile: string);
var
inF, ouF, zpF: TStream;
buf: array[1..1024]of char;
begin
inF:=TFileStream.Create(InFile, fmOpenRead);
ouF:=TFileStream.Create(OutFile, fmCreate);
zpF:=TCompressionStream.Create(clMax, ouF)
//clDefault
zpF.CopyFrom(inF, 0);

zpF.Free;
inF.Free;
ouF.Free;
end;

procedure DecompressFile(Infile, OutFile: string);
var
inF, ouF, zpF: TStream;
buf: array[1..1024]of char;
i: integer;
begin
inF:=TFileStream.Create(Infile, fmOpenRead);
ouF:=TFileStream.Create(OutFile, fmCreate);
zpF:=TDecompressionStream.Create(inF);
i:=zpF.Read(buf, 1024);
while i>0 do begin
ouF.Write(buf, i);
i:=zpF.Read(buf, 1024);
end;

ouF.Free;
zpF.Free;
inF.Free;
end;


 
MyMs是什么呀!
Ms.LoadFromFile('c:/123.jmi');//是我压缩后的文件假设里面含有三个文件,把它打开
...
Ms.Position :=0;
Fs.CopyFrom(Ms,MyInt)//假设第一个文件大小是MyInt.
Ms.Position :=0

DecompressStream(Fs,MyMs);//解压第一个文件
MyMs.SaveToFile(MyFile);//保存第一个文件(为什么这个文件是空的!!!)
还有Ms等在创建的时候注意参数;
 
卡色,:对不起是我写错了
MyMs是什么呀!
是MyMsFile
 
你在 Fs.CopyFrom(Ms,MyInt)//假设第一个文件大小是MyInt. 后面加一行
Ms.Position := 0;
试一试?
 
beta,:一样的!
 
procedure DecompressStream(inpStream, outStream: TStream);//解压过程
var
InpBuf, OutBuf: Pointer

OutBytes, sz: Integer

begin
InpBuf := nil

OutBuf := nil

sz := inpStream.Size - inpStream.Position

if sz > 0 then
try
GetMem(InpBuf, sz)

inpStream.Read(InpBuf^, sz)

DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes)

outStream.Write(OutBuf^, OutBytes)

finally
if InpBuf <> nil then FreeMem(InpBuf)

if OutBuf <> nil then FreeMem(OutBuf)

end

outStream.Position := 0

end


procedure TForm1.Button3Click(Sender: TObject);
var
Ms,MyMsFile,Fs:TMemoryStream;
MyFile:string;
MyInt:integer;
begin
Ms:=TMemoryStream.Create ;
MyMsFile:=TMemoryStream.Create ;
Fs:=TMemoryStream.Create ;
try

Ms.LoadFromFile('c:/123.jmi');//是我压缩后的文件假设里面含有三个文件,把它打开
...
Ms.Position :=0;
Fs.CopyFrom(Ms,MyInt)//假设第一个文件大小是MyInt.
DecompressStream(Fs,MyMsFile);//解压第一个文件
MyMsFile.SaveToFile(MyFile);//保存第一个文件(为什么这个文件是空的!!!)
FINALLY
Ms.Free;
MyMsFile.Free ;
Fs.Free;
end;
end;
 
Fs.CopyFrom(Ms,MyInt)//假设第一个文件大小是MyInt.
[red]ShowMessage(IntToStr(Fs.Size));[/red]
DecompressStream(Fs,MyMsFile);//解压第一个文件
[red]ShowMessage(IntToStr(MyMsFile.Size));[/red]

看看两个各是多少?
 
beta, 前面一个是文件的大小,后面一个是0
 
说明你的 DecompressStream 有问题!

 
procedure DecompressStream(inpStream, outStream: TStream);//解压过程
var
InpBuf, OutBuf: Pointer

OutBytes, sz: Integer

begin
InpBuf := nil

OutBuf := nil

sz := inpStream.Size - inpStream.Position

if sz > 0 then
try
GetMem(InpBuf, sz)

inpStream.Read(InpBuf^, sz)

DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes);
[red]ShowMessage(IntToStr(OutBytes));[/red] // 看看这个是多少?
outStream.Write(OutBuf^, OutBytes)

finally
if InpBuf <> nil then FreeMem(InpBuf)

if OutBuf <> nil then FreeMem(OutBuf)

end

outStream.Position := 0

end

 

// [red]ShowMessage(IntToStr(OutBytes));[/red] // 看看这个是多少?

没有报告,没有执行到这句!
 
倒~~~那问题应该出在这里了:
sz := inpStream.Size - inpStream.Position

直接改成
inpStream.Position := 0;
sz := inpStream.Size;

然后再看那个 ShowMessage(IntToStr(OutBytes))
是多少。
 

Similar threads

I
回复
0
查看
450
import
I
I
回复
0
查看
648
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
579
import
I
顶部