The missing Find (POS) feature in the Delphi XE7 array operation

Source: Internet
Author: User

In Delphi Xe7, there are many extensions to array operations, such as the addition of string-like functions.

For example, the array is added

var  a:array of Integer;  B:tbytes = [1,2,3,4]; Initialization can be do from Declarationbegin ...  a:=[1,2,3]; Assignation using constant array  a:=a+[4,5];//Addition-a'll become [1,2,3,4,5]  ... end;

Array insertion

var  a:array of Integer;begin ...  a:=[1,2,3,4];  Insert (5,a,2); A'll become [1,2,5,3,4]  ... end;

Array deletion

var  a:array of Integer;begin ...  a:=[1,2,3,4];  Delete (a,1,2); A'll become [1,4]  ... end;

Array connections

A: = Concat ([1,2,3],[4,5,6]); A'll become [1,2,3,4,5,6]

Why in the Xe7 to make such a big change in the array, of course, first of all, it must be convenient to set up the programming, in fact, the reason for the deeper layer is because the ansistring on the mobile platform is missing,

A lot of the past code, because all of the byte as Ansichar processing, to the mobile platform, the code will not run up. And it's hard to change.

Then only use tbytes to replace the traditional ansistring. So the array operation adds so many methods to solve this traditional problem.

That is now the problem, the traditional POS functionality has not been added, resulting in a large number of operations using POS can not be modified.

I didn't know it was in xe? Add it inside? Now the temporary way is to do a find (POS) function to solve this problem.

In order not to conflict with future POS, the function name is called Find, the function is to find another array inside an array, and return to the location.

function Find (const SUB, buffer:tbytes): Integer;var  n:integer;begin  N: = Length (sub);  If N>0 then    in Result: = Low (buffer) to high (buffer)-(N-1) does      if Comparemem (@Buffer [Result], Sub, N)        Then Exit;  Result: = -1;end;

This can be used to replace the original Ansistring POS operation.

The missing Find (POS) feature in the Delphi XE7 array operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.