[Gambas-user] _compare() Type mismatch: wanted Date, Number or String

Tobias Boege tobiasboege01 at ...1601...
Tue Jul 31 22:46:08 CEST 2012


On Tue, 31 Jul 2012, Patrik Karlsson wrote:
> I'm writing a class for Playing cards and would like to compare them with:
> =,<,>.
> 
> While hPlayingCard1=hPlayingCard2 works just fine,
> hPlayingCard1<hPlayingCard2 and hPlayingCard1>hPlayingCard2 do not.
> 
> The program stops with:
> #6: Type mismatch: wanted Number, Date or String, got PlayingCard instead
> 
> My _compare is simple:
> Public Function _compare(OtherObject As PlayingCard) As Integer
> 
>     Return 0
> 
> End
> 
> What can I do to make comparing with <,> possible?
> 
> /patrik

If I got the documentation[0] right, the <,> are only valid for the native
classes you are given in the error message: Number, Date, String.
It is also said[1] that _compare() is used for sorting arrays of objects on
a class or finding those. It could likely mean - ignoring the "for example"
in that sentence - that these arithmetic operators are not related to the
_compare() method.

IIRC, there was discussion[2] about a new special method _operator() on the
gambas-devel list which will enable you to use any operator on a _native
class_. Actually, this seems to be implemented in the gb.gsl classes
already. I don't know if it is intended for classes written in Gambas, too.
At least, there is no documentation about it (at the usual place) and the
commit messages didn't show me anything.

[0] http://gambasdoc.org/help/cat/arithop?v3
[1] http://gambasdoc.org/help/lang/special/compare?v3
[2] http://old.nabble.com/About-gb.gsl-components-td34130245.html

Regards,
Tobi




More information about the User mailing list