BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TList.Sort

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi ObjectPascal
View previous topic :: View next topic  
Author Message
Mainlander
Guest





PostPosted: Tue Sep 23, 2003 12:08 am    Post subject: TList.Sort Reply with quote




I have a class that I designed that contains some objects in its fields,
that are derived from the TList class.

I want to use the TList Sort procedure to sort the items that are in the
derived class. The derived class has an extra field that specifies how to
sort the items.

The problem I have is in the implementation of the Sort method in the way
the class is implemented by Borland. The call to the Sort method must
pass in the name of a simple procedure. The procedure call then receives
the pointers to the two items that it must return the order of.

Why oh why could Borland have not implemented the sort procedure call as
an event procedure or allow a method of another object to be passed as
the parameter to the Sort call, because I want the sort procedure to be
able to read the extra field in my class so that it knows how to carry
out the sort.

As the sort procedure does not receive any information about the calling
object there are various un-OO fudges like global variables necessary to
enable the sort procedure to get this information which I would like to
eliminate. I have been able to discover that it is not possible to pass a
class method in the sort procedure.
Back to top
Trevor
Guest





PostPosted: Wed Sep 24, 2003 7:00 pm    Post subject: Re: TList.Sort Reply with quote



Mainlander <*@*.*> wrote in
news:MPG.19da56351ab6fc42989d39 (AT) news (DOT) paradise.net.nz:

Quote:

I have a class that I designed that contains some objects in its
fields, that are derived from the TList class.


<snip>

Quote:

As the sort procedure does not receive any information about the
calling object there are various un-OO fudges like global variables
necessary to enable the sort procedure to get this information which I
would like to eliminate. I have been able to discover that it is not
possible to pass a class method in the sort procedure.

It's just a callback function. This should work.

function SizeCompare(objA, objB : pointer) : integer;
begin
if ((objA as TWhatever).Size > (objB as TWhatever).Size) then
Result := 1
else if ((objA as TWhatever).Size < (objB as TWhatever).Size) then
Result := -1
else
Result := 0;
end;


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Back to top
Mainlander
Guest





PostPosted: Wed Sep 24, 2003 9:36 pm    Post subject: Re: TList.Sort Reply with quote



In article <Xns940098E61CB93trevorokesympaticoca (AT) 209 (DOT) 25.157.130>,
[email]trevor.oke (AT) pullmyfinger (DOT) sympatico.ca[/email] says...
Quote:
Mainlander <*@*.*> wrote in
news:MPG.19da56351ab6fc42989d39 (AT) news (DOT) paradise.net.nz:


I have a class that I designed that contains some objects in its
fields, that are derived from the TList class.


snip


As the sort procedure does not receive any information about the
calling object there are various un-OO fudges like global variables
necessary to enable the sort procedure to get this information which I
would like to eliminate. I have been able to discover that it is not
possible to pass a class method in the sort procedure.

It's just a callback function. This should work.

function SizeCompare(objA, objB : pointer) : integer;
begin
if ((objA as TWhatever).Size > (objB as TWhatever).Size) then
Result := 1
else if ((objA as TWhatever).Size < (objB as TWhatever).Size) then
Result := -1
else
Result := 0;
end;

You miss the point. The objects passed in are items of a TList. The
information I want is stored in a property of that TList. Unless there is
a way of getting the TList object then it is a waste of time.

The TStringList customsort method allows the object instance to be passed
permitting this very thing. The TListView and TTreeview components both
have an event handler defined, OnCompare, which of course passes the
object instance as the Sender parameter.


Back to top
Jeremy Collins
Guest





PostPosted: Thu Sep 25, 2003 7:38 am    Post subject: Re: TList.Sort Reply with quote

Mainlander wrote:

Quote:
You miss the point. The objects passed in are items of a TList. The
information I want is stored in a property of that TList. Unless there is
a way of getting the TList object then it is a waste of time.

So write a TList descendent that uses a different Sort callback.


--
jc

Remove the -not from email


Back to top
Trevor
Guest





PostPosted: Thu Sep 25, 2003 5:05 pm    Post subject: Re: TList.Sort Reply with quote

Mainlander <*@*.*> wrote in
news:MPG.19dcd53efa034988989d46 (AT) news (DOT) paradise.net.nz:


Quote:
You miss the point. The objects passed in are items of a TList. The
information I want is stored in a property of that TList. Unless there
is a way of getting the TList object then it is a waste of time.

The TStringList customsort method allows the object instance to be
passed permitting this very thing. The TListView and TTreeview
components both have an event handler defined, OnCompare, which of
course passes the object instance as the Sender parameter.


Ah. I see what you mean now.

I'm going to agree with Jeremy and suggest that you just descend from
TList and give it the functionality that you want.

T


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Back to top
Mainlander
Guest





PostPosted: Thu Sep 25, 2003 11:24 pm    Post subject: Re: TList.Sort Reply with quote

In article <8Ywcb.3836$%G1.766 (AT) newsfep4-winn (DOT) server.ntli.net>,
[email]jd.collins (AT) ntlworld-not (DOT) com[/email] says...
Quote:
Mainlander wrote:

You miss the point. The objects passed in are items of a TList. The
information I want is stored in a property of that TList. Unless there is
a way of getting the TList object then it is a waste of time.

So write a TList descendent that uses a different Sort callback.

How do I do that without the source code to TList?

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi ObjectPascal All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.