Delphi array initialization

后端 未结 3 860
挽巷
挽巷 2021-01-04 01:19

I currently have this, and it sucks:

type TpointArray = array [0..3] of Tpoint;

class function rotationTable.offsets(pType, rotState, dir: integer): TpointA         


        
3条回答
  •  天命终不由人
    2021-01-04 02:06

    Arrays of records can be intialised in const expressions:

    const
      Points : TPointArray = ((X: 1; Y: 1), (X:1; Y:2), (X:1; Y:1), (X:1; Y:1));
    
    class function rotationTable.offsets(pType, rotState, dir: integer): TpointArray;
    begin
       Result := Points;
    end;
    

    In XE7 it is possible to fill a dynamic array of records like this:

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

提交回复
热议问题