delphi XE7 数组操作中缺少的find(POS)功能
delphi xe7 中对数组操作做了很多扩充,比如加入了类似字符串处理的功能。
例如,数组相加
var
A: array of integer;
B: TBytes = [1,2,3,4]; //Initialization can be done from declaration
begin
...
A:=[1,2,3]; // assignation using constant array
A:=A+[4,5]; // addition - A will become [1,2,3,4,5]
...
end;
数组插入
var
A: array of integer;
begin
...
A:=[1,2,3,4];
Insert(5,A,2); // A will become [1,2,5,3,4]
...
end;
数组删除
var
A: array of integer;
begin
...
A:=[1,2,3,4];
Delete(A,1,2); //A will become [1,4]
...
end;
数组连接
A := Concat([1,2,3],[4,5,6]); //A will become [1,2,3,4,5,6]
为什么在xe7 中要对数组做这么大的变化呢,当然首先肯定是方便数组编程,其实更深层的原因是因为ansistring 在移动平台上的缺失,
很多过去的代码,由于都是把byte 当作ansichar 处理的,到了移动平台上,这些代码都跑不起来了。而且很难改造。
那么只有使用Tbytes 里替换传统的ansistring. 因此对数组操作增加了这么多方法来解决这个传统问题。
那现在问题来了,传统的pos 功能却没加入,导致大量的是使用pos 的操作无法改造。
不知道会在xe? 里面加入?现在临时的办法就是自己做一个find(pos)函数来解决这个问题。
为了不与以后的pos 冲突,函数名就叫find, 功能是在一个数组里面查找另一个数组,并返回位置。
function Find(const sub, Buffer:TBytes): Integer;
var
N: Integer;
begin N := Length(sub);
if N>0 then
for Result := low(Buffer) to high(Buffer)-(N-1) do
if CompareMem(@Buffer[Result], sub, N) then
exit;
Result := -1;
end;
这样就可以用这个替换原来的ansistring 的pos 操作了。
其实也可以做成helper 更方便用。
TBytesHelper = record helper for Tbytes
public
procedure setlength(len:integer);
function Find(const sub:TBytes): Integer;
procedure add(const buff:TBytes); end; procedure TBytesHelper.add(const buff: TBytes);
begin
self:=self+buff;
end; function TBytesHelper.Find(const sub: TBytes): Integer;
var
len: Integer;
begin
len:= Length(sub);
if len>0 then
for Result := low(self) to high(self)-(len-1) do
if CompareMem(@self[Result], sub, len) then
exit;
Result := -1;
end; procedure TBytesHelper.setlength(len: integer);
begin System.setlength(self,len);
end;
delphi XE7 数组操作中缺少的find(POS)功能的更多相关文章
- 关于delphi XE7中的动态数组和并行编程(第一部分)
本文引自:http://www.danieleteti.it/category/embarcadero/delphi-xe7-embarcadero/ 并行编程库是delphi XE7中引进的最受期待 ...
- Delphi XE7试用记录2
Delphi XE7试用记录2 万一博客中介绍了不少Delphi7以后的新功能测试,想跟着测试一下.每次测试建立一个工程,在窗体上放几个按钮,测试几个相关的功能,这样虽然简单明了,但日后查阅起来不方便 ...
- Delphi XE7中使用JSON
Delphi XE7有一个对JSON处理的单元,在你需要使用JSON的单元里面引入"System.json",随后你就可以用Delphi自己的json处理类了.我写的小例子只是对包 ...
- RemObjects SDK Source For Delphi XE7
原文:http://blog.csdn.net/tht2009/article/details/39545545 1.目前官网最新版本是RemObjects SDK for Delphi and al ...
- delphi XE7 中的消息
在delphi XE7的程序开发中,消息机制保证进程间的通信. 在程序中,消息来自: 1)系统: 通知你的程序用户输入,涂画以及其他的系统范围的事件: 2)你的程序:不同的程序部分之间的通信信息. ...
- 咏南CS多层插件式开发框架支持最新的DELPHI XE7
DATASNAP中间件: 中间件已经在好几个实际项目中应用,长时间运行异常稳定,可无人值守: 可编译环境:DELPHI XE5~DELPHI XE7,无需变动代码: 支持传统TCP/IP方式也支持RE ...
- Delphi XE7中新并行库
Delphi XE7中添加了新的并行库,和.NET的Task和Parellel相似度99%. 详细内容能够看以下的文章: http://www.delphifeeds.com/go/s/119574 ...
- Delphi XE7下如何创建一个Android模拟器调试
利用Delphi XE7我们可以进行多种设备程序的开发,尤其是移动开发应用程序得到不断地加强.在实际的Android移动程序开发中,如果我们直接用android真机直接调试是非常不错.一是速度快,二是 ...
- DELPHI XE7 新的并行库
DELPHI XE7 的新功能列表里面增加了并行库System.Threading, System.SyncObjs. 为什么要增加新的并行库? 还是为了跨平台.以前要并行编程只能从TThread类继 ...
随机推荐
- Eclipse中java文件和jsp字体大小设置
1.更改java文件大小设置Window->preferences->General->Appearance->Colors and Fonts->Java-&g ...
- HTML网页Table解析
procedure TForm27.Button1Click(Sender: TObject); var doc2: IHTMLDocument2; doc3: IHTMLDocument3; ita ...
- 字典(dictionary) 的基本操作
info = { ’stu1101‘ : ’xiaoming’, ‘stu1102 : xiahong‘, ’stu1103 : ‘xiaozhi', } 1. 字典的获取 info.get('stu ...
- Haskell语言学习笔记(54)Data.Set
Data.Set Prelude> import Data.Set as Set Prelude Set> :set -XOverloadedLists Construction Prel ...
- (3)shiro自定义realm
上面一章说到shiro的认证和授权最底层就是调用realm的getAuthorizationInfo(获取用户的角色和资源)和getAuthenticationInfo(校验账号密码是否正确)两个方法 ...
- go语言channel的别样用法
1.返回值使用通道 func main() { // 生成随机数作为一个服务 randService := randGenerator() // 从服务中读取随机数并打印 fmt.Printf(&qu ...
- js中定时器之一
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Anaconda中python加入环境变量
1.我的电脑---高级系统设置 2.选中环境变量,保存. 3.在系统环境变量PATH中,加入Anaconda3及Script路径加入其中 4.测试python
- 使用Navicat Premium连接mysql数据库
Navicat Premium是一个可多重连接的数据库管理工 具,它可让你以单一程序同时连接. Navicat Premium 使你能简单并快速地在各种数据库系统间传输数据,或传输一份指定 SQL 格 ...
- OOP的几个不常用的方法
from OOP_多态 import cat c = cat("cat") print(c.__doc__) print(cat.__doc__) # # 打印类的描述信息,也就是 ...