type

type

  TMyEnum = (One, Two, Three);

  TMyObject = class

  public type

    TItems = array[TMyEnum] of String;

  private

    FItems: TItems;

  public

    property Items:TItems read FItems write FItems; default;

  end;

 [dcc32 Error] E2132 Default property must be an array property

There probably is a good reason for this, but I am still annoyed 😛

15 thoughts on “type


  1. Then there is this variation


      TMyEnum = (One, Two, Three);


      TMyObject = class


      public type


        TItems = array[TMyEnum] of String;


      private


        FItems: TItems;


      public


        property Items[Index:TMyEnum]:String read FItems[Index] write FItems[Index]; default; ♠


      end;


    ♠ [dcc32 Error] E2003 Undeclared identifier: ‘Index’


  2. And if you write a setter and a getter method with an Index parameter? I think read/write methods are required for indexers or array properties.


  3. And that is exactly what I mean when I say the compiler should be able to support more syntax sugar. Obviously the compiler knows what is missing here and should be able to generate the missing code.


  4. Stefan Glienke Well, what if I _wanted_ to return a TItems, not just index into it? The second suggestion from Lars Fosdal could work though.


  5. The default array property should be indexed as an integer value, not an enumeration. The getter/setter signature is fixed to be an “integer” by the compiler intrinsics, I guess.


  6. A. Bouchez – There is no problem using an enumerated index for a default array propery if you have the get and/or set methods.


      TMyEnum = (One, Two, Three);


      TMyObject = class


      public type


        TItems = array[TMyEnum] of String;


      private


        FItems: TItems;


        function GetItems(Index: TMyEnum): String;


        procedure SetItems(Index: TMyEnum; const Value: String);


      public


        property Items[Index:TMyEnum]:String read GetItems write SetItems; default;


      end;


    My “grind” is that setters and getters that do nothing but 


    procedure GetItems(Index: TMyEnum):String


    begin


      Result := FItems[Index];


    end;


    really should not be required.


  7. Lars Fosdal All getters and setters that don’t do anything but redirect access should be figured out by the compiler imo. The syntax in the property declaration is expressive enough to avoid any ambiguity.


  8. Oh, and then you have this little tidbit:


    property One: String index TMyEnum.One read GetItems write SetItems;


    which might as well have been


    property One: String read FItems[TMyEnum.One] write FItems[TMyEnum.One];

Leave a Reply