Autor Beitrag
Alpha_Wolf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 297

Ubuntu, Win XP, Win Vista
C#, Delphi 6 Prof, Delphi 2007 Prof, Java
BeitragVerfasst: Sa 19.08.06 12:54 
Hallo Leute,

ich würde gerne eine TList sortieren allerdings nicht nach ihren direkten Inhalten sondern nach einem Item des hinterlegten Records:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
type
  PSortedCompanyRecord = ^TSortedCompanyRecord;
  TSortedCompanyRecord = record
    GUID       : string;
    RecordIx   : integer;
  end;
  .
  .
  fSortedCompanyRecord: ^TSortedCompanyRecord;
  fSortedCompanyList: TList;


Die Liste fülle ich zB so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  .
  .
  new(fSortedCompanyRecord);
  fSortedCompanyRecord.GUID       := lCompanyGUID;  // z.B.: C3B6DED207F44052BBD59EF67F62DF13
  fSortedCompanyRecord.RecordIx   := lCompanyRecIX; // z.B.: 4
  fSortedCompanyList.Add(fSortedCompanyRecord);
  .
  .


Nun möchte ich die Liste nach dem GUID Item des Records sortieren.
Kann mir da jemand helfen?

Vielen Dank für eure Hilfe.

_________________
Diskutiere nie mit einem Irren - er zieht dich auf sein Niveau und schlägt dich mit seiner Erfahrung.
Phantom1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: Sa 19.08.06 15:11 
Müsste so hier gehen:

ausblenden Delphi-Quelltext
1:
fSortedCompanyList.Sort(@CompareGUID);					


die callback function "CompareGUID" sieht so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
function CompareGUID(Item1, Item2: Pointer): Integer;
begin
  Result:=CompareText(PSortedCompanyRecord(Item1)^.GUID, PSortedCompanyRecord(Item2)^.GUID);
end;


mfg
Alpha_Wolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 297

Ubuntu, Win XP, Win Vista
C#, Delphi 6 Prof, Delphi 2007 Prof, Java
BeitragVerfasst: Sa 19.08.06 16:14 
Vielen Dank Phantom1 funktioniert einwandfrei =)

Schönes Wochenende noch!

_________________
Diskutiere nie mit einem Irren - er zieht dich auf sein Niveau und schlägt dich mit seiner Erfahrung.