![]() |
TList.Sort führt zu Stacküberlauf
Eigentlich habe ich es so gemact wie in den Beispielen auch, nur bekomme ich einen Stacküberlauf:
Delphi-Quellcode:
FContactList ist eine TList.
function CustomCompare(Item1, Item2: Pointer): Integer;
var Contact1: TContact; Contact2: TContact; begin Result := 0; Contact1 := TContact(Item1); Contact2 := TContact(Item2); if Contact1.FName > Contact2.FName then Result := 1 else Result := -1; procedure TContactCollection.SortContacts; begin FContactList.Sort(CustomCompare); end; Aufruf mit:
Delphi-Quellcode:
procedure TfrmAdressen.FillListbox;
var i : Integer; begin lbContacts.Clear; //ContactCollection.MySort; ContactCollection.SortContacts; for i := 0 to ContactCollection.Count - 1 do begin lbContacts.Items.AddObject('ItemCaption', ContactCollection.Items[i]) end; end; |
Re: TList.Sort führt zu Stacküberlauf
Bei Gleichheit liefert die Funktion nicht 0, sondern -1. Verwende lieber CompareStr bzw. CompareText.
|
Re: TList.Sort führt zu Stacküberlauf
Mist, das hab eich übersehen. Aber mit CompareStr ist es viel einfachher. Danke für den Tipp.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:46 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz