ZLib for Kylix

By: Matthias Thoma

Abstract: Here's how you can get Delphi's TDecompressionStream and TCompressionStream classes to work with Kylix. By Matthias Thoma.

Unfortunately Borland does not provide Delphi's TCompressionStream and TDecompressionStream classes for Kylix. In some applications they may be necessary and having them under Linux can be important for the Delphi-Kylix compatibility. Luckily, it is not too hard to port them to Kylix yourself using the Project JEDI zlib Header conversion. It can be found on the Kylix companion CD-ROM and at CodeCentral: ID 15583.

To make it more comfortable it is the best to create a new unit for the stream wrappers, but of course you can also make the changes in the zlib.pas file directly.

First you'll have to create a new unit and call it zlibstream.pas. Add the file zlib to your uses clause. It should now read:

uses
  SysUtils, Classes, zlib;

Copy the following classes and types from Delphi's zlib.pas to the interface section of zlibstream.pas:

  • TCustomZLibStream
  • TCompressionStream
  • TDecompressionStream
  • TCompressionLevel
  • procedure CompressBuf
  • procedure DecompressBuf

Don't forget the exception type declarations EZLibError, ECompressionError, and EDecompressionError.

Now you will have to fill the implementation section. Just copy all the members of the classes CustomZLibStream, TCompressionStream, TDecompressionStream, and the functions or procedures CompressBuf, DecompressBuf, _memset, _memcpy, zlibAllocMem, zlibFreeMem, CCheck and DCheck.

Last but not least, you'll have to change every line which contains inflateinit_. The second parameter has changed from string to PChar, so you should make a simple typecast:

inflateInit_ (...) PChar(zlib_version) (...)

That's it! Have fun with your new cross-platform TCompressionStream and TDecompressionstream.

If you have any questions, comments or suggestions regarding this article please feel free to contact me.

Server Response from: SC4