加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi数组初始化

发布时间:2020-12-15 10:13:37 所属栏目:大数据 来源:网络整理
导读:我目前有这个,它吸吮: type TpointArray = array [0..3] of Tpoint;class function rotationTable.offsets(pType,rotState,dir: integer): TpointArray;begin Result[0] := point(1,1); Result[1] := point(1,2); Result[2] := point(1,1); Result[3] := p
我目前有这个,它吸吮:
type TpointArray = array [0..3] of Tpoint;

class function rotationTable.offsets(pType,rotState,dir: integer): TpointArray;
begin

  Result[0] := point(1,1);
  Result[1] := point(1,2);
  Result[2] := point(1,1);
  Result[3] := point(1,1);
end;

而是我想做这样的事情:

class function rotationTable.offsets(pType,dir: integer): TpointArray;
begin
   Result := [Point(1,1),Point(1,2),1)];
end;

但是,在编译时,它抱怨说[1,2,3,4]语法只适用于整数。

有没有办法实例化/初始化一个类似于我想要的方式的Tpoint数组?

解决方法

记录数组可以在const表达式中进行初始化:
const
  Points : TPointArray = ((X: 1; Y: 1),(X:1; Y:2),(X:1; Y:1),(X:1; Y:1));

class function rotationTable.offsets(pType,dir: integer): TpointArray;
begin
   Result := Points;
end;

在XE7中,可以填充动态的记录数组,如下所示:

function GetPointArray: TArray<TPoint>;
begin
  Result := [Point(1,1)];
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读