您好,欢迎光临本网站![请登录][注册会员]  
文件名称: delphi字符串压缩
  所属分类: Delphi
  开发工具:
  文件大小: 298kb
  下载次数: 0
  上传时间: 2012-08-06
  提 供 者: yeeo****
 详细说明: unit main; interface {********************************************************************* 压缩测试单元 作者:崔东伟 Email:cuidongwei@yeah.net 或 s72002004@yahoo.com.cn 发布这一文件的目的是希望它有用,但没有任何担保。甚至没有适合特定目的 而隐含的担保。作者不承担由此带来的任何问题 *********************************************************************} uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons; const BufferSize=2048; type Tmainfm = class(TForm) Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; BitBt n1: TBitBtn; BitBtn2: TBitBtn; GroupBox1: TGroupBox; BitBtn3: TBitBtn; BitBtn4: TBitBtn; GroupBox2: TGroupBox; BitBtn5: TBitBtn; BitBtn6: TBitBtn; GroupBox3: TGroupBox; BitBtn7: TBitBtn; BitBtn8: TBitBtn; GroupBox4: TGroupBox; BitBtn10: TBitBtn; BitBtn11: TBitBtn; OpenDialog1: TOpenDialog; SaveDialog1: TSaveDialog; Memo1: TMemo; Label3: TLabel; procedure BitBtn3Click(Sender: TObject); procedure BitBtn1Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var mainfm: Tmainfm; implementation {$R *.DFM} uses lz77,arith,zlib,lh5unit; procedure ZCompress(InStr, OutStr: TStream); var Zstream:TCustomZlibStream; CompressionLevel:TCompressionLevel; begin CompressionLevel:=clMax; ZStream := TCompressionStream.Create(CompressionLevel, OutStr); try ZStream.CopyFrom(InStr, 0); finally ZStream.Free; end; end; procedure ZExpand(InStr, OutStr: TStream); var Zstream:TCustomZlibStream; Buffer : Array[0 .. BufferSize - 1] of Byte; count:integer; begin ZStream := TDecompressionStream.Create(InStr); try while True do begin Count := ZStream.Read(Buffer, BufferSize); if Count <> 0 then OutStr.WriteBuffer(Buffer, Count) else Break; end; finally ZStream.Free; end; end; procedure Tmainfm.BitBtn3Click(Sender: TObject); const cstr:array[1..8] of string= ('lz77Compress', 'lz77Expand', 'ArithCompress', 'ArithExpand', 'LHACompress', 'LHAExpand', 'ZCompress', 'ZExpand'); var infn,outfn:string; infile,outfile:TStream; begin infn:=Edit1.text; if not fileexists(infn) then raise exception.Create('源文件不存在!'); outfn:=Edit2.text; if fileexists(outfn) then begin if application.messagebox('输出文件已经存在,要覆盖该文件吗?', '警告',MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON2)=IDNO then exit; deletefile(outfn); end; InFile := TFileStream.Create(infn, fmOpenRead); try OutFile := TFileStream.Create(outfn, fmCreate); try case TComponent(Sender).tag of 1:lz77Compress(Infile,OutFile); 2:lz77Expand(Infile,OutFile); 3:ArithCompress(Infile,OutFile); 4:ArithExpand(Infile,OutFile); 5:LHACompress(Infile,OutFile); 6:LHAExpand(Infile,OutFile); 7:zCompress(Infile,OutFile); 8:zExpand(Infile,OutFile); end; if TComponent(Sender).tag in [1,3,5,7] then memo1.Lines.add(format('%s 输入%d :bytes 输出:%d bytes 压缩比:%5.2f', [cstr[TComponent(Sender).tag],InFile.size,outfile.size,outfile.size*100/InFile.size])+'%') else memo1.Lines.add(format('%s 输入%d :bytes 输出:%d bytes 压缩比:%5.2f', [cstr[TComponent(Sender).tag],InFile.size,outfile.size,InFile.size*100/outfile.size])+'%'); finally outfile.free; end; finally InFile.Free; end; end; procedure Tmainfm.BitBtn1Click(Sender: TObject); begin if OpenDialog1.Execute then edit1.Text:=OpenDialog1.FileName; end; procedure Tmainfm.BitBtn2Click(Sender: TObject); begin if SaveDialog1.Execute then edit2.Text:=SaveDialog1.FileName; end; end. ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: delphi 字符串 压缩
 输入关键字,在本站1000多万海量源码库中尽情搜索: