Creates a slice of an array as an Open Array parameter System unit
 function Slice ( SourceArray : array; Count : Integer ) : array;
The Slice function creates a sub-array from the first Count elements of an array, SourceArray.
It can ONLY be used as an argument for an 'Open array' parameter of a procedure or function.
An 'Open array' parameter is one that has an unknown number of array elements at compile time.
This allows for a routine to work with variable sized arrays.
Related commands
Array A data type holding indexable collections of data
Copy Create a copy of part of a string or an array
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Passing an array slice to a procedure
  i : Integer;
  Source : array[0..4] of Integer;

  // Create the source array with 0..4 values for elements 0..4
  for i := 0 to 4 do
    Source[i] := i;

  // Use the Slice command to pass just the first 3 elements of Source as
  // an open array to the ShowSlice procedure below.
  ShowSlice(Slice(Source, 3));

// Show an array of unknown size - it is passed as an 'Open' array
procedure TForm1.ShowSlice(SubArray : array of Integer);
  i : Integer;

  // Show every element of this array
  for i := 0 to Length(SubArray)-1 do
    ShowMessage('SubArray['+IntToStr(i)+'] : '+ IntToStr(SubArray[i]));
Show full unit code
   SubArray[0] : 0
   SubArray[1] : 1
   SubArray[2] : 2
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page