Delphi的流对象(TStream的派生对象)有如下读写函数:

function Read(var Buffer; Count: Longint): Longint;
function Write(const Buffer; Count: Longint): Longint;
procedure ReadBuffer(var Buffer; Count: Longint);
procedure WriteBuffer(const Buffer; Count: Longint);

Buffer是Var或const类型,它们都是无类型参数,所以对其处理都使用指针.

通常我们会用流来处理长的字符串,但是用字符串类型作为Buffer参数会导致错误的结果.

因为字符串包括大小,引用计数,字符存储地址等信息.为了在流中正确处理字符串,要将其转为Pointer对或PChar.

示例如下:

var
 s1,s2:string;
 MemStream:TMemoryStream;
begin
  MemStream:=TMemoryStream.Create;
  s1:='this is a string test!';
  MemStream.SetSize(length(s1));
  MemStream.Write(PChar(s1)^,length(s1));
  SetLength(s2,length(s1));
  MemStream.Position:=0;
  MemStream.Read(PChar(s2)^,length(s1));
  ShowMessage(s2);
  MemStream.Clear;
  MemStream.Free;
end;

http://www.cnblogs.com/dashan9zj/archive/2009/01/14/1375261.html

最新文章

  1. td的所有style
  2. Codeforces Round #359(div 2)
  3. javaScript事件(四)event的公共成员(属性和方法)
  4. nodejs7-buffer
  5. Event Sourcing
  6. jquery提交form表单插件jquery.form.js
  7. RxJS 实现摩斯密码(Morse) 【内附脑图】
  8. API网关-Ocelot概述
  9. 【进阶3-1期】JavaScript深入之史上最全--5种this绑定全面解析(转)
  10. bootstrapTable
  11. 研究C语言的新型编译环境TCC
  12. 【转】Kylin系列-使用Saiku+Kylin构建多维分析OLAP平台
  13. 使用django实现自定义用户认证
  14. Sqlserver2008及以上使用全文索引排除干扰词 (转载)
  15. Android开发之获取手机SIM卡信息
  16. SSL证书部署
  17. openerp发送给群组信息
  18. python批量给云主机配置安全组
  19. java如何计算两个经纬度之间的距离?
  20. P1613 跑路

热门文章

  1. 【t084】数列
  2. 【codeforces 760C】Pavel and barbecue
  3. Innodb单表数据物理恢复
  4. Graphics-Processing Architecture Based on Approximate Rendering
  5. radio实现第一次点击选中第二次点击取消
  6. hadoop 3.x 配置日志聚集功能
  7. ListView 泛利
  8. 线性方程组的求解(C++)
  9. Obtaining Directory Change Notifications(微软的例子,使用FindFirstChangeNotification,FindNextChangeNotification,FindCloseChangeNotification API函数)
  10. python爬虫 BeautifulSoup