Board index » delphi » TList sort function cannot be a class function

TList sort function cannot be a class function

I have noticed that if my TList sort function is a class function
that the function does not work properly.  Since class functions are
suppose to be just like normal functions I consider this a compiler bug.  
Has anyone else noticed this?

--
     Mike Vance

 

Re:TList sort function cannot be a class function


Mike,

Class functions are not just like normal functions - they all
receive an undeclared, hidden parameter: Self. This is documented,
and therefore can't be considered a bug.

HTH

Ken
--
Ken White
kwh...@westelcom.com

Clipper Functions for Delphi
http://members.aol.com/clipfunc/

Quote
Mike Vance wrote:

> I have noticed that if my TList sort function is a class function
> that the function does not work properly.  Since class functions are
> suppose to be just like normal functions I consider this a compiler bug.
> Has anyone else noticed this?

> --
>      Mike Vance

Re:TList sort function cannot be a class function


Hi,

Quote
>I have noticed that if my TList sort function is a class function

Do you mean method, i.e. function declared inside a class?

Quote
>Since class functions are suppose to be just like normal functions

Who supposes that? Methods take a hidden parameter named self pointing
to the instance for which the method is called.

While it would be nice in some places to be able to pass a method as a
comparing function it is not declared that way.

The opposite is true BTW for event handlers, they have to be methods
not ordinary procedures or functions.

Quote
>I consider this a compiler bug.

I think you should reconsider.

Ciao, MM
--
Marian Maier, Gamma Soft, Hainstra?e 8, 53121 Bonn, Germany
Tel: +49 228 624013 Fax: +49 228 624031
http://www.gammasoft.de/maier
"Was schiefgehen kann geht schief"

Re:TList sort function cannot be a class function


I am referring to class functions in the form of:
        class function MyFunc: Integer;
Not methods belonging to a class.

Class functions should receive no "undeclared, hidden parameter: Self"
since they never reference any object.

Or do they?  Is there something quirky about Delphi that I need to know
about?  My knowledge of class functions stems from C++ and I figured
Delphi would operate in a similar manner.

--
     Mike Vance

Re:TList sort function cannot be a class function


Quote
Mike Vance wrote in message ...
>I am referring to class functions in the form of:
> class function MyFunc: Integer;
>Not methods belonging to a class.

>Class functions should receive no "undeclared, hidden parameter: Self"
>since they never reference any object.

>Or do they?  Is there something quirky about Delphi that I need to know
>about?  My knowledge of class functions stems from C++ and I figured
>Delphi would operate in a similar manner.

The only think quirky, to my knowledge, is the fact that Delphi lets you
compile a (non-class) procedure or function with the 'class' keyword
specified. The 'class' keyword for procedures and functions is meaningless
outside of the context of a class.

Within a class, a class method is one that operates on the class *type*
rather than any class *instance* and Self refers to the class type rather
than the instance.

For your purposes (a TList sort "callback"), you need to specify a simple
function as specified in the help for this:

function MySortCompare(Item1, Item2: Pointer): Integer;

--
Wayne Niddery - WinWright Consulting
Delphi, C++Builder, JBuilder, InterDev --
http://home.ican.net/~wniddery/RADBooks.html
...remove chaff when replying...
"You know you've landed gear-up when it takes full power to taxi"

Re:TList sort function cannot be a class function


Okay, I'll use a non-class function, but it would of been nice to
organize regular functions under classes as "class functions"

--
     Mike Vance

Other Threads