March 2000
Intermediate to advanced
576 pages
18h 13m
English
Slice Function
function Slice(var A: array; Count: Integer): array;
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.
// 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;| Array Keyword, Copy Function, Type Keyword |
Read now
Unlock full access