Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#1

TList.Sort führt zu Stacküberlauf

  Alt 28. Mär 2009, 17:51
Eigentlich habe ich es so gemact wie in den Beispielen auch, nur bekomme ich einen Stacküberlauf:
Delphi-Quellcode:
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;
FContactList ist eine TList.

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;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat