Pass a multidimensional array as a parameter in Delphi

前端 未结 4 1397
你的背包
你的背包 2021-01-20 15:17

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         


        
4条回答
  •  执笔经年
    2021-01-20 15:38

    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);
    ...
    

    (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.

提交回复
热议问题