请无忧鱼来拿分!!!(100分)

  • 主题发起人 主题发起人 zhangjianbo
  • 开始时间 开始时间
Z

zhangjianbo

Unregistered / Unconfirmed
GUEST, unregistred user!
TO :无忧鱼
非常关注你在 [red]http://www.delphibbs.com/delphibbs/dispq.asp?lid=2073567 [/red] 中的回贴,
你在回贴中有这样的语句在中间层调用解压缩、解密数据代码Mydata:=DeCompress(mydata);
我也用了这样的代码,就是不正确,
公用代码:
function MemoryStreamToOleVariant(Strm: TMemoryStream): OleVariant;
var
Data: PByteArray;
begin
Result := VarArrayCreate([0, Strm.Size - 1], varByte);
Data := VarArrayLock(Result);
try
Strm.Position := 0;
Strm.ReadBuffer(Data^, Strm.Size);
finally
VarArrayUnlock(Result);
end;
end;

function OleVariantToMemoryStream(OV: OleVariant): TMemoryStream;
var
Data: PByteArray;
Size: integer;
begin
Result := TMemoryStream.Create;
try
Size := VarArrayHighBound (OV, 1) - VarArrayLowBound(OV, 1) + 1;
Data := VarArrayLock(OV);
try
Result.Position := 0;
Result.WriteBuffer(Data^, Size);
finally
VarArrayUnlock(OV);
end;
except
Result.Free;
Result := nil;
end;
end;

{ 压缩 Stream }
procedure CompressStream(inpStream, outStream: TMemoryStream);
var
InpBuf, OutBuf: Pointer;
InpBytes, OutBytes: Integer;
begin
InpBuf := nil;
OutBuf := nil;
try
GetMem(InpBuf, inpStream.Size);
inpStream.Position := 0;
InpBytes := inpStream.Read(InpBuf^, inpStream.Size);
CompressBuf(InpBuf, InpBytes, OutBuf, OutBytes);
outStream.Write(OutBuf^, OutBytes);
finally
if InpBuf <> nil then
FreeMem(InpBuf);
if OutBuf <> nil then
FreeMem(OutBuf);
end;
end;

{ 解压缩 stream }
procedure DecompressStream(inpStream, outStream: TMemoryStream);
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;

服务器端:
Function Mycompress(Oledata:OleVariant) :Olevariant;
var
tmpStream ,tmpstream1: TMemoryStream;
tmpdata :olevariant;
begin
tmpstream :=OleVariantToMemoryStream(oledata);
CompressStream(tmpstream,tmpstream1);
tmpdata := MemoryStreamToOleVariant(tmpstream1);
Result := tmpdata;
end;

客户端:
Function MyDecompress(Oledata:OleVariant) :Olevariant;
var
detmpStream ,detmpstream1: TMemoryStream;
begin
detmpstream :=OleVariantToMemoryStream(oledata);
DecompressStream(detmpstream,detmpstream1);
Result :=MemoryStreamToOleVariant(detmpstream1);
end;

客户端和服务器的使用的方法应该和你的一样,不加上面的压缩部分时,程序都能正确运行,但加了压缩就会出错.
TO:无忧鱼 我的问题出错在那里,若错误无法排除,通否将你实现压缩和加密部分的代码传给我,若分不够,我可再加分.
我是邮箱:jianbo-zhang@163.com
期待你的回音!!!
 
TO:无忧鱼
我看到你在线,能来看一下这个问题吗?
谢谢!!!
 
后退
顶部