delphi XE6 –使用Android的zlib  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi XE6 –使用Android的zlib


我在Delphi XE6中编写了与“ Team Japan»C ++ Builder XE6 –使用iOS / Android的zlib ” 相同的过程。

我确认可以使用Delphi XE6和Nexus7进行操作。
我认为它也可以在iOS上使用。

在窗体上放置两个按钮,两个TEdit和一个TLabel。
按下“写入”按钮时,在TEdit中输入的字符串将压缩为UTF-8字节字符串并保存。

uses System.IOUtils, System.ZLib;

procedure TForm1.Button1Click(Sender: TObject);
var
  FN: string;
  Bytes: TBytes;
  FS: TFileStream;
  CS: TZCompressionStream;
begin
  FN := System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetDocumentsPath(),
    'test.gz');

  FS := TFileStream.Create(FN, fmCreate);
  CS := TZCompressionStream.Create(FS);

  Bytes := TEncoding.UTF8.GetBytes(Edit1.Text);
  CS.Write(Bytes, Length(Bytes));

  Bytes := TEncoding.UTF8.GetBytes(Edit2.Text);
  CS.Write(Bytes, Length(Bytes));

  CS.Free;
  FS.Free;
end;
按下“读取”按钮时,将读取并恢复压缩和保存的数据。

procedure TForm1.Button2Click(Sender: TObject);
var
  FN: string;
  DS: TZDecompressionStream;
  FS: TFileStream;
  Bytes: TBytes;
begin
  FN := System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetDocumentsPath(), 'test.gz');

  FS := TFileStream.Create(FN, fmOpenRead);
  DS := TZDecompressionStream.Create(FS);
  SetLength(Bytes, DS.Size);
  DS.Position := 0;
  DS.Read(Bytes, DS.Size);
  DS.Free;
  FS.Free;

  Label1.Text := TEncoding.UTF8.GetString(Bytes);
end;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.054064035415649 seconds