通过多维数组作为德尔福参数 [英] Pass a multidimensional array as a parameter in Delphi
问题描述
我想一个多维数组传递给构造函数,像这样:
I'd like to pass a multi-dimensional array to a constructor like so:
constructor TMyClass.Create(MyParameter: array of array of Integer);
begin
LocalField := MyParameter;
end;
在哪里LocalField是整型数组的数组。
Where LocalField is an array of array of Integer.
不过上述code不会编译('标识,但却发现ARRAY')。可能有人向我解释为什么这是错的?我试过在开放,动态和静态数组读了,但还没有找到一些作品。有没有办法解决它在不改变LocalField的类型?
However the above code won't compile ('Identifier expected but ARRAY found'). Could somebody explain to me why this is wrong? I tried reading up on open, static and dynamic arrays but have yet to find something that works. Is there a way to fix it without changing the type of LocalField?
推荐答案
请为localfield一个特定的类型,然后设置,作为MyParameter的类型,沿着线的东西:
Make a specific type for localfield, then set that as the type of MyParameter, something along the lines of:
type
TTheArray = array[1..5] of array[1..10] of Integer;
var
LocalField: TTheArray;
constructor TMyClass.Create(MyParameter: TTheArray);
...
(注:在编译器中不核实,小错误可能是present)
(Note: not verified in a compiler, minor errors may be present)
请注意,大部分经常在帕斯卡的语法多维数组更正确地声明为
Note that most often in pascal-like syntax a multidimensional array is more properly declared as
type
TTheArray = array[1..5, 1..10] of Integer;
当然,除非,你有一些很好的理由这样做的其他方式。
Unless, of course, you have some good reason for doing it the other way.
这篇关于通过多维数组作为德尔福参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!