简体   繁体   中英

Zlib in Delphi 2009

I am upgrading a app to Delphi 2009. The app uses Soap and we compress the soap request and response streams using Zlib. This works fine in Delphi 2006 but not in Delphi 2009.

So I went back to Delphi 2006 and changed to use FastZlib. It all worked fine in Delphi2006 but does not work in Delphi 2009 and I get Decompress errors.

Has anyone else had this problem?

How do I go about fixing this?

Sandeep

in D2009 you can use ZCompress/ZDecompress instead of CompressBuf/DecompressBuf
I test it and there is no problem.

The original poster's was clear about the problem: CompressBuf and DecompressBuf are GONE.

I also have a project that compiles just fine in D7, but fails to compile in D2010 because it can't find "CompressBuf" or "DecompressBuf".

A search using D7's very pleasant find command locates the routines at c:\\Program Files\\Borland\\Delphi7\\Source\\Rtl\\Common\\ZLib.pas

But searching with D2010's (awkward separate) "Find in Files" command fails to locate CompressBuf or DecompressBuf anywhere.

It's very disturbing that upgrading the IDE causes routines used and needed in projects to disappear!

I just looked through the built-in Zlib.pas and it appears to have been updated for D2009 properly. What's giving you problems?

In delphi 2006 I had following methods to compress and decompress using Zlib(from Delphi 2006)

procedure CompressStream(inpStream, outStream: TStream);
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;


{ Decompress a stream }
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;

What should I change for these to work in Delphi 2009?

Something that might be worth trying - compress your data, and then UUENCODE it, and on the other end, reverse the process. This will detect if some code is not dealing with embedded zero's properly.

Sorry, this is only a partial solution to help you narrow the problem down.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM