Hello!

Hello!

So I have this interface in Delphi XE:

IUserList = interface
  ['{A9E4DC2D-CDEA-4B5C-8A68-8086D7800455}']
    function GetUser( const Index : Integer ) : TUserClass;
    procedure NewUser( IP : String );
    procedure AddUser( ID: Integer;Token : String;EmployeeLevel : Integer;ProfileName : String );
    function FindUser( IP : String ) : TUserClass;
    property Users[ Index : Integer ] : TUserClass read GetUser;
  end;

When I try to compile the project, Delphi XE complains that GetUser doesn't have an open bracket. Sigh!

Doesn't make sense to me.

Anybody knows what's going on?

Thanks!

A

Comments

  1. I got `[DCC Error] Unit1.pas(15): E2008 Incompatible types`.
    This works: get rid of the `const`:

    unit Unit1;

    interface

    type
      TUserClass = class

      end;
      IUserList = interface
      ['{A9E4DC2D-CDEA-4B5C-8A68-8086D7800455}']
        function GetUser(  Index : Integer ) : TUserClass;
        procedure NewUser( IP : String );
        procedure AddUser( ID: Integer;Token : String;EmployeeLevel : Integer;ProfileName : String );
        function FindUser( IP : String ) : TUserClass;
        property Users[ Index : Integer ] : TUserClass read GetUser;
      end;

      implementation

    end.

    ReplyDelete
  2. Groan... today isn't a good day is it?

    Thanks!

    A

    ReplyDelete
  3. Andrea Raimondi I think it is a known coding convention, but I could not find a documentation link on it yet.

    ReplyDelete
  4. I've seen something like this before where the compiler accepted the code, but then the compiled code using the indexed property never called the Get method - silently. That took a while to track down :/

    In that situation removing the const fixed it too.

    ReplyDelete
  5. Jeroen Wiert Pluimers Are you saying, then, that by "convention" you mean that the const specification is illegal there? I think I would spell that "defect"...

    ReplyDelete
  6. Bill Meyer
    The problem is that the property getter includes a const modifier for Index but the property declaration didn't. If you want to make the parameter for the index const, then it needs to be so when declaring the property too:

    property Users[const Index : Integer ] : TUserClass read GetUser;

    ReplyDelete
  7. Chris Rolliston Ah, I see. One of those things I could easily miss. I shall have to see whether MMX handles it properly.

    ReplyDelete
  8. Remove keyword const from parameter declaration 
    e.g.  function GetUser( Index : Integer ) :

    ReplyDelete

Post a Comment