朝花朝拾

朝花昔时杯中酒

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
< 2025年1月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8

Slice 函数

 

function Slice(var A: array; Count: Integer): array;
Slice函数把数组 A的前面Count个元素作为开放数组返回, 利用它可以方便的使用动态分配的
静态数组而且保持Delphi的数组的使用优点..
例子:
type
  TPolygon = record
    NumPoint: 0..MaxInt;
    Points  : array[1..MAX_POINTS] of TPoint;
  end;

procedure DrawPolygon(Canvas: TCanvas; const Polygon: TPolygon);
begin
  Canvas.Polygon(Slice(Polygon.Points, Polygon.NumPoint));
end;




Returns a sub-section of an array.
Unit
System
Category
miscellaneous routines
function Slice(var A: array; Count: Integer): array;
Description
Use Slice to select a sub-section (slice) of an array to be passed as an open array parameter. Slice is only allowed as a parameter in a call to a procedure or function that expects an open array parameter. Slice selects the first Count elements of the array given by A to be passed as an open array parameter. A can be an open array parameter itself, allowing dynamically allocated arrays to be passed to open array parameters.
posted on   朝花朝拾  阅读(716)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示