Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi TStringList absteigend sortieren? (https://www.delphipraxis.net/2368-tstringlist-absteigend-sortieren.html)

design5 20. Jan 2003 10:08


TStringList absteigend sortieren?
 
Hallo,

ich habe mir eine TSringList erstellt die folgende Werte ausgibt:

'0234=Hugo'
'1257=Oli'
'0021=Egon'
'6745=Bob'

Mit der Funktion namensliste.sort; bringt er mir bei der Ausgabe die Daten alle aufsteigend sortiert.

Gibt es ein Befehl, der die Ausgabe auch absteigend sortiert ermöglicht?

poy 20. Jan 2003 10:20

wenn du die liste mit sort sortiert hast, kanst du die strings mit Exchange(Index1, Index2: Integer); austauschen.
ist nicht gerade eine schöne lösug, sollte abr funktionieren.
stehe nämlich vor dem selben problem habe es so gelöst.
wäre aber auch froh, wenn man dies anders lösen kann.

design5 20. Jan 2003 10:32

Quasi den ersten Eintrag gegen den letzten tauschen, usw. Wäre eine Möglichkeit aber in meinem Fall keine gute Lösung. Das Programm sollte später mal DB-Einträge auf Ähnlichkeit untersuchen (xx.000 Einträge). Wenn ich die dann alle noch umsortiere, brauch das Suchergebnis nochmal länger...

Trotzdem danke.

poy 20. Jan 2003 10:37

füllst du die StringListe direkt aus der datenbank via SQL?

wenn ja, du kannst die SQL-abfrage schon sortieren und dann der Reihe nach in die Liste einfügen
dies geht mit dem SQL-befehl SORT

design5 20. Jan 2003 10:56

Auch wieder recht, noch gar nicht bedacht!

Daniel 20. Jan 2003 11:03

Hallo,

erstmal willkommen in der Delphi-PRAXiS. :P

Die Stringliste bietet Dir die Eigenschaft 'CustomSort' an, mit welcher Du sie in einer von Dir gewünschten Reihenfolge sortieren kannst.

Zitat:

Zitat von Delphi-Hilfe
Sorts the strings in the list in a customized order.

Delphi-Quellcode:
type TStringListSortCompare = function(List: TStringList; Index1, Index2: Integer): Integer;
procedure CustomSort(Compare: TStringListSortCompare); virtual;
Description:
Use CustomSort to sort the strings in the list, where the sort order is defined by the Compare parameter.

Supply a value for the Compare function that compares two strings in the string list. The List parameter provides access to the string list, while the Index1 and Index2 parameters identify the strings to be compared. Use Index1 and Index2 as indexes into the Strings property array. The Compare function should return

a value less than 0 if the string identified by Index1 comes before the string identified by Index2
0 if the two strings are equivalent
a value greater than 0 if the string with Index1 comes after the string identified by Index2.
Do not pass nil as the value of the Compare parameter.

Note: You must explicitly call the CustomSort method. Setting the Sorted property only sorts strings using ANSI order, as implemented in the Sort method.


grayfox 24. Jan 2003 21:41

hallo daniel!

Stringlist.CustomSort gibts aber erst ab D6 Personal, in D4 hab ich es vergeblich gesucht. ich dachte schon bedenken, dass mir da was ganz praktisches entgangen sei ...

mfg, stefan

Christian Seehase 24. Jan 2003 22:45

Moin Stefan,

nur zur Info:
D5 kennt CustomSort auch schon.


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:16 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz