Name

Slice Function

Syntax

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

Description

Slice returns the first Count elements of the array A as an argument for an open array parameter. The only time you can use Slice is when passing an array to a subroutine. The Slice function is a convenient way to use a dynamically allocated static array and still keep the advantages of Delphi arrays.

Slice is not a real function.

Example

// A drawing package stores a polygon with up to MAX_POINTS points.
// A TPolygon record stores the array of vertices and the number
// of points in the polygon. DrawPolygon draws the polygon on a canvas.
type
  TPolygon = record
    NumPoints: 0..MaxInt;
    Points: array[1..MAX_POINTS] of TPoint;
    end;
procedure DrawPolygon(Canvas: TCanvas; const Polygon: TPolygon);
begin
  Canvas.Polygon(Slice(Polygon.Points, Polygon.NumPoints));
end;

See Also

Array Keyword, Copy Function, Type Keyword
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset