Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-02

Strange behaviour about class properties

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Adrian Maier

Hello,

I have the following class :

  FDK_record = class
      private
         TABLE: FDK_table;
         procedure SET_COLUMN    ( field_index: integer;  field_value: string );
         function  GET_COLUMN    ( field_index: integer ): string ;
         procedure SET_COLUMN ( field_name: string;  field_value: string );
         function  GET_COLUMN ( field_name: string ): string ;
      public
         STATUS : fdk_record_status;
         VALUES : array of string;
         NR_FIELDS : integer;
         constructor CREATE( t: FDK_table ; s: fdk_record_status );
         property VALUE_BY_NAME [filed_name : string ]  : string  read
get_column write set_column ; default;
   end;

I don't understand why the following usage works :

 r:=mytable.GET_RECORD(6);    { this returns a FDK_record }
 r[0]:='BZBZB';

Since the default property is VALUE_BY_NAME , which is referenced by a string, why does
it work with an integer index ? It should accept only string indexes !

It looks like the property's index type (string) is not enforced at all : if the given
index is integer it simply uses the integer version of GET_COLUMN and SET_COLUMN .

Having overloaded functions seems to fool the compiler into accepting any kind of argument , as long as there is an overloaded function matching its type.

Is this a bug or a feature ?

Cheers,
Adrian Maier

Reply by email