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 android实例-读取设备联系人(xe8+小米2)

Delphi调用sql分页存储过程实例

Delphi 让程序只运行1次

Delphi 闪盘小偷

Delphi绘制标题栏

Delphi 多关键词批量替换

Delphi 拷贝文件夹内所有内容

Delphi 双击关闭pagecontrol中的一个分页

Delphi 代替pos的函数

Delphi 读取正在被占用的txt文件

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



打赏

取消

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

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

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

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

评论

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