Delphi中流对象的应用
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
最新文章
- td的所有style
- Codeforces Round #359(div 2)
- javaScript事件(四)event的公共成员(属性和方法)
- nodejs7-buffer
- Event Sourcing
- jquery提交form表单插件jquery.form.js
- RxJS 实现摩斯密码(Morse) 【内附脑图】
- API网关-Ocelot概述
- 【进阶3-1期】JavaScript深入之史上最全--5种this绑定全面解析(转)
- bootstrapTable
- 研究C语言的新型编译环境TCC
- 【转】Kylin系列-使用Saiku+Kylin构建多维分析OLAP平台
- 使用django实现自定义用户认证
- Sqlserver2008及以上使用全文索引排除干扰词 (转载)
- Android开发之获取手机SIM卡信息
- SSL证书部署
- openerp发送给群组信息
- python批量给云主机配置安全组
- java如何计算两个经纬度之间的距离?
- P1613 跑路
热门文章
- 【t084】数列
- 【codeforces 760C】Pavel and barbecue
- Innodb单表数据物理恢复
- Graphics-Processing Architecture Based on Approximate Rendering
- radio实现第一次点击选中第二次点击取消
- hadoop 3.x 配置日志聚集功能
- ListView 泛利
- 线性方程组的求解(C++)
- Obtaining Directory Change Notifications(微软的例子,使用FindFirstChangeNotification,FindNextChangeNotification,FindCloseChangeNotification API函数)
- python爬虫 BeautifulSoup