[fpc-pascal] Strange behaviour about class properties
Adrian Maier
adrian.maier at gmail.com
Thu Feb 7 09:55:53 CET 2008
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
More information about the fpc-pascal
mailing list