在C++ Builder中使用Delphi附带的Zlib封装类
来源:互联网 发布:剑三苍云正太捏脸数据 编辑:程序博客网 时间:2024/05/01 07:10
论坛帖子:http://community.csdn.net/Expert/topic/3288/3288152.xml?temp=.2455866
Delphi附带的zlib.pas包括了两个压缩和解压流的辅助类。使用起来相当方便,这使得很多C++ Builder的使用者都想要使用这个zlib.pas,偏偏borland没有在BCB中带上这个东西。也许可能是担心C++社群对BCB进行攻击吧。哈~(我一直也认为本来就是C的源码,非要用pascal来封装,呵呵,特别怪啊)
不过得分要紧,而且Indy 9也使用了zlib的开放原始码,和zlib.pas的做法如出一辙,
肯定是有人抄袭 -_-|||。
由于delphi中使用了dcu来提高编译速度,所以borland并没有提供可供重新编译zlib.pas任何相关的obj文件。本来我们需要下载zlib的原始码,自己来动手编译。不过既然我记得indy 9里面有相同的obj,这一步就不用了。去http://www.indyproject.org/download/Borland.html 下载一个原始码。
解压出所需的obj文件和zlib.pas放在同一目录下,就可以成功的使用bcb来编译这个pas了,哈~
{$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} |
就是上面几个。
现在我们可以和使用其他的vcl类一样来使用了。
顺便给出我测试的代码:
#include "ZLib.hpp" void CompressFile( AnsiString FileName, AnsiString CompressedFileName) { TFileStream *FIn, *FOut; TCompressionStream* C; if(!FileExists(FileName)) throw Exception("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 Count; if(!FileExists(FileName)) throw Exception("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); } } //--------------------------------------------------------------------------- |
- 在C++ Builder中使用Delphi附带的Zlib封装类
- Delphi使用Zlib、C++Builder使用Zlib
- 在C++BUILDER中应用ZLIB
- 在C++BUILDER中应用ZLIB
- 在Delphi中使用ZLib的最新版本
- 如何在C++Builder中使用Delphi控件
- C++Builder中使用Excel的类
- C++Builder中TIniFile类的使用
- 在C++Builder中使用GDI+的流程
- C++builder中使用第三方Delphi安装包注意事项
- 如何在C++Builder中使用ACE
- 如何在C Builder中使用全局变量
- 如何在C++Builder中使用全局变量
- GDI+ 在Delphi、C++Builder程序的应用 -- IStream
- 使用DELPHI / C++BUILDER XE2 UPDATE 2 XX的风险
- 怎样在C++Builder中创建使用DLL
- 在 C++Builder 2006 中使用 Indy10 控件!
- 在c++builder中使用createoleobject函数时?
- 查找数据表的主键
- 8/1~~8/19
- JAVA内部类
- RSS 2.0 Resolver Class Beta 2
- 急!求救!!!请教关于sql server启动的问题
- 在C++ Builder中使用Delphi附带的Zlib封装类
- .Net编程技巧集锦
- C++: The Most Powerful Language for .NET Framework Programming
- 程序员,你的路好走吗?(二)
- 用Flash结合ASP制作计数器
- FLASH结合ASP进行对数据库的操作
- css现状
- "网络编程"学习笔记(2)
- struts中文的解决『文摘』