delphi System.SysUtils.TMarshaller 与 System.TMarshal


本文整理自网络,侵删。

 System.SysUtils.TMarshaller 与 System.TMarshal

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

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


{测试}
procedure TForm1.FormCreate(SenderTObject);
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 通�^窗口句柄或窗口标题得到进程句柄

Delphi 判断字符串是否相同

Delphi 详解 enumwindows 与 enumwindowsproc

Delphi写的播放器核心代码,播放mp3无压力

Delphi中updown组件的使用方法

Delphi的cpu调试窗口

Delphi内嵌汇编语言basm精要

Delphi常用数据类型

Delphi 取16进制字符的10进制的integer值

Delphi 图像灰度化处理

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



打赏

取消

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

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

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

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

评论

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

    暂无评论...