Delphi XE6 �C使用Android的zlib


本文整理自网络,侵删。

 
我在Delphi XE6中编写了与“ Team Japan?C ++ Builder XE6 ?C使用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;

相关阅读 >>

Delphi idhttp数据自动编码

Delphi 弹窗显示sql字符串

Delphi 读取软件卸载信息和桌面图标列表

Delphi 拖动文件到exe 打开 获取getcommandline命令行

Delphi 常用函数单元 umyfunctions

Delphi程序与chm帮助关联的简单实现

Delphi注册与卸载系统服务

Delphi 获取文件创建时间

Delphi getfileversion 获取文件版本

Delphi wm_copydata 用法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...