假如有个函数 function MyFun(const arr: array of Integer): Integer;
调用代码:num := MyFun([1,2,3]);
问题:函数要求的参数类型是 是一数组常量,可是在调用的时候传递的是[1,2,3],这不是个集合类型的吗?
难道[1,2,3] 可以表示数组常量么,不解?
还有 定义数组常量是这样定义的啊
const
 MyArr:Array of integer = (1,2,3);
那传递常量数组参数的时候为什么不这样呢,即:num := MyFun((1,2,3));发现Delphi中()和[]的用法很是迷惑,盼大虾指点,谢谢!

解决方案 »

  1.   

    数组声明是这样的arr:array [0..2] of Integer;
      

  2.   


    const 
      MyArr:Array [0..2] of integer = (1,2,3);
      

  3.   

    刚刚看到 帮助
    NoteIn some function and procedure declarations, array parameters are represented as array of baseType, without any index types specified. For example,function CheckStrings(A: array of string): Boolean;This indicates that the function operates on all arrays of the specified base type, regardless of their size, how they are indexed, or whether they are allocated statically or dynamically.
    有所理解,但是为什么传参数的时候 要传递[1,2,3]呢?
      

  4.   

    自己搞定了,还是要看帮助,呵呵
    Open array constructors allow you to construct arrays directly within function and procedure calls. They can be passed only as open array parameters or variant open array parameters.An open array constructor, like a set constructor, is a sequence of expressions separated by commas and enclosed in brackets. For example, given the declarationsvar I, J: Integer;
    procedure Add(A: array of Integer);you could call the Add procedure with the statementAdd([5, 7, I, I + J]);This is equivalent tovar Temp: array[0..3] of Integer;
     ...
    Temp[0] := 5;
    Temp[1] := 7;
    Temp[2] := I;
    Temp[3] := I + J;
    Add(Temp);Open array constructors can be passed only as value or const parameters. The expressions in a constructor must be assignment-compatible with the base type of the array parameter. In the case of a variant open array parameter, the expressions can be of different types.