delphi – 如何在pascal中不使用for循环的情况下一次设置多个数
发布时间:2020-12-15 09:25:48 所属栏目:大数据 来源:网络整理
导读:我正在学习Pascal并且目前遇到了关于数组操作的问题.我遇到过一种设置数组的方法,我已经在其他语言中看到了,但我不知道如何在Pascal中做类似的事情. 变量的声明看起来像这样: rotationBounds: array of array of integer;setLength(rotationBounds,5,5); 我
我正在学习Pascal并且目前遇到了关于数组操作的问题.我遇到过一种设置数组的方法,我已经在其他语言中看到了,但我不知道如何在Pascal中做类似的事情.
变量的声明看起来像这样: rotationBounds: array of array of integer; setLength(rotationBounds,5,5); 我想做这样的事情: rotationBounds := [ [0,0],[0,1,]; 基本上,我试图直接设置一个多维数组,而不是循环遍历它. 我的一个重点是使它看起来像一张图片,易于阅读和理解. 有没有办法可以实现这样的目标? 我正在使用Borland Delphi 6来编译程序. 解决方法
在Delphi 6中,没有内置的动态数组初始化支持.我会使用一对辅助函数:
type TIntegerArray = array of Integer; TIntegerMatrix = array of TIntegerArray; function IntegerArray(const Values: array of Integer): TIntegerArray; var i: Integer; begin SetLength(Result,Length(Values)); for i := 0 to high(Result) do Result[i] := Values[i]; end; function IntegerMatrix(const Values: array of TIntegerArray): TIntegerMatrix; var i: Integer; begin SetLength(Result,Length(Values)); for i := 0 to high(Result) do Result[i] := Values[i]; end; 然后像这样调用它: var rotationBounds: TIntegerMatrix; .... rotationBounds := IntegerMatrix([ IntegerArray([0,0]),IntegerArray([0,]); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |