Slice Function
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.
// 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;