delphi System.SysUtils.TMarshaller 与 System.TMarshal


本文整理自网络,侵删。

 System.SysUtils.TMarshaller 与 System.TMarshal

TMarshaller(结构) 基于 TMarshal(是有一大堆的 class 方法组成的类) 实现.
TMarshaller 可以对缓存区进行自动(自动释放)安全地管理, TMarshal 也有前者没有的重要方法, 譬如: TMarshal.Copy() 方法.

有了它们, 以后关于内存缓冲区, 字符串转码等操作就更方便了.
--------------------------------------------------------------------------------


{测试}
procedure TForm1.FormCreate(Sender: TObject);
var
  M: TMarshaller;
  pw: TPtrWrapper;
  str: string;
  bs: TBytes;
begin
  bs := BytesOf('万一的 Delphi 博客');

  pw := M.AllocMem(Length(bs));

  TMarshal.Copy(bs, 0, pw, Length(bs));

  str := TMarshal.ReadStringAsAnsi(pw);
  ShowMessage(str);

  pw := M.AsUtf8(str);

  str := TMarshal.ReadStringAsUtf8(pw, -1);
  ShowMessage(str);
end;
--------------------------------------------------------------------------------

相关阅读 >>

Delphi timagelist 中使用 透明 png 图标

Delphi中case语法的使用方法

Delphi idhttp友好错误信息的捕获

Delphi程序升级到64位

Delphi保存读取utf-8的文本文件

Delphi 获取指定当前目录下指定文件扩展名所有文件

Delphi 10.3.1新的变量的声明方法

Delphi 间隔时间

Delphi tdsauthenticationmanager的用法

Delphi 获取文件所在路径

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



打赏

取消

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

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

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

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

评论

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