1. Computing
Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link Back

Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
 

Slice

unit
System
category
Miscellaneous routines

declaration
function Slice(var A: array; Count: Integer): array;

description
Returns a sub-section of an array.

Slice is only allowed as a parameter in a call to a procedure or function that expects an open array parameter.

example
function Sum(const A: array of integer): integer;
var i, S: Integer;
begin
  S := 0;
  for i := 0 to High(A) do S := S + A[i];
  Result := S;
end;

...

const anArray : array[0..9] of integer = (1,2,3,4,5,6,7,8,9,10);
var IntSum : integer;
begin
  IntSum := Sum(anArray); //55  == 1+2+3+..+9+10
  IntSum := Sum(Slice(anArray,5)); //15 == 1+2+3+4+5
end;

in real code

see also


 Free Delphi code snippet inside every Delphi Newsletter!
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?

©2013 About.com. All rights reserved.