| View previous topic :: View next topic |
| Author |
Message |
Mainlander Guest
|
Posted: Tue Sep 23, 2003 12:08 am Post subject: TList.Sort |
|
|
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
|
Posted: Wed Sep 24, 2003 7:00 pm Post subject: Re: TList.Sort |
|
|
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
|
Posted: Wed Sep 24, 2003 9:36 pm Post subject: Re: TList.Sort |
|
|
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
|
Posted: Thu Sep 25, 2003 7:38 am Post subject: Re: TList.Sort |
|
|
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
|
Posted: Thu Sep 25, 2003 5:05 pm Post subject: Re: TList.Sort |
|
|
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
|
Posted: Thu Sep 25, 2003 11:24 pm Post subject: Re: TList.Sort |
|
|
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 |
|
 |
|