Autor Beitrag
LittleBen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: So 30.10.11 10:44 
Hallo,
ich möchte eine TStringlist nach ihren Werten aus der "zweiten Spalte" sortieren (StrToInt(sl.ValueFromIndex[nPos])).
Diese Werte sind alle numerisch.
Wie mache ich das am besten?

Viele Grüße,
Benny
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: So 30.10.11 11:15 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
function CompareZahl(const A, B: Double):Integer;
begin
  if A =B then Result := 0
  else if A < B then
    Result := -1
  else
    Result := 1;
end;

function CompareValueIsInt(List: TStringList; Index1, Index2: Integer ):Integer;
var
  i1,i2:Integer;
begin
     if TryStrToInt(List.ValueFromIndex[index1],i1) and TryStrToInt(List.ValueFromIndex[index2],i2) then
       Result := CompareZahl(i1, i2)
     else Result := 0;
end;



procedure TlistBox.Sort(p:CompareProc);
var
  sl:TStringList;
begin
  sl := TStringList.Create;
  try
       sl.Assign(Items);
       sl.CustomSort(@p);
       Items.Assign(sl);
  finally
    sl.Free;
  end;

end;

ListBox1.Sort(@CompareValueIsInt);

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS

Für diesen Beitrag haben gedankt: LittleBen