Use the Zlib package class with Delphi in C ++ Builder

xiaoxiao2021-03-06  108

Forum Posts: http://community.9cbs.net/expert/topic/3288/3288152.xml? Temp = .2455866

Zlib.Pas included with Delphi includes two auxiliary classes of compression and decompression streams. It is quite convenient to use, which makes many C Builder users want to use this zlib.pas, and Borland does not bring this on the BCB. Maybe it may be worried that the C community attacked BCB. Ha ~ (I have always thought that it was C's source code, I have to pack it with PASCAL, huh, especially blame)

However, the score is tight, and INDY 9 also uses Zlib's open original code, and Zlib.Pas practice is exactly the same, it must be plagiarized --_- |||.

Since DELPHI uses DCU to increase compilation speed, Borland does not provide any related OBJ files for recompiling Zlib.Pas. Originally, we need to download the original code of ZLIB, you can write it yourself. But since I remember the same OBJ in Indy 9, this step is not available. Go to http://www.indyproject.org/download/borland.html to download a raw code.

Unzip the required obj files and zlib.pas placed in the same directory, you can successfully use BCB to compile this PAS, ha ~

{$ L deflate.obj}

{$ L inflate.obj}

{$ L InfTrees.obj}

{$ L TREES.OBJ}

{$ L adler32.obj}

{$ L infblock.obj}

{$ L infcodes.obj}

{$ L infutil.obj}

{$ L inffast.obj}

It is the above.

Now we can use it with other VCL classes.

By the way, give the code I test:

#include "zlib.hpp"

Void CompressFile (Ansistring FileName, Ansistring CompressedFileName)

{

TFileStream * fin, * fout;

TcompressionStream * C;

IF (fileexists (fileEname) "" File Not Exist ");

FIN = New TfileStream (FileName, FmopenRead | fmsharedenywrite);

Fout = NULL;

IF (FileExists (CompressedFileName))

Fout = New TFileStream (CompressedFileName, FMOpenWrite | FMShareExClusive);

Else

Fout = New TFileStream (CompressedFileName, FMCReate | FMShareExClusive);

Try

{

C = New TcompressionStream (ZLIB :: CLmax, Fout);

Try

{

C-> CopyFrom (FIN, 0);

}

__finally

{

Delete C;

}

}

__finally

{

Delete fin;

Delete fout;

}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void DecompressFile (Ansistring FileName, Ansistring DecompressedFileName)

{

TFileStream * fin, * fout;

TDECompressionStream * D; Byte BUF [4096];

INT country;

IF (fileexists (fileEname) "" File Not Exist ");

FIN = New TfileStream (FileName, FmopenRead | fmsharedenywrite);

Fout = NULL;

IF (FileExists (DecompressedFileName)

Fout = New TFileStream (DecompressedFileName, FMOpenWrite | FMShareExClusive);

Else

Fout = New TFileStream (DecompressedFileName, Fmcreate | FMShareExClusive);

Try

{

D = New TDECompRessionsTream (FIN);

Try

{

For (count = 1; count> 0;)

{

Count = D-> Read (BUF, SIZEOF (BUF));

Fout-> Write (buf, count);

}

}

__finally

{

Delete D;

}

}

__finally

{

Delete fin;

Delete fout;

}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tform1 :: button1click (Tobject * Sender)

{

IF (OpenDialog1-> Execute () && savedialog1-> execute ())

{

CompressFile (OpenDialog1-> FileName, Savedialog1-> FileName);

}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tform1 :: button2click (Tobject * Sender)

{

IF (OpenDialog1-> Execute () && savedialog1-> execute ())

{

DecompressFile (OpenDialog1-> FileName, Savedialog1-> filename);

}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

转载请注明原文地址:https://www.9cbs.com/read-125268.html

New Post(0)