Autor Beitrag
minipliman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Do 22.12.05 12:32 
wie sotier ich 6 zahlen in einer listbox die im berreich von 1 bis 49 liegen? normal sotiert er ja nach ascii ich will aber nach dem zahlenwert sotieren.


Moderiert von user profile iconGausi: Topic aus Sonstiges verschoben am Do 22.12.2005 um 13:47
Angel4585
Hält's aus hier
Beiträge: 7


Delphi 2005 Prof.
BeitragVerfasst: Do 22.12.05 12:42 
wandel beim vergleichen die strings in zahlen um(StrToInt(Listbox1.items.strings[]))
dann müssts gehen.
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Do 22.12.05 14:19 
zum Beispiel so !
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure ListIntegerSort (List : TStrings);
var i,j : Integer;
    tempString : String;
begin
  for i := 0 to List.Count -1 do
    for j := 0 to List.Count -1 do
      if StrToInt(List[j]) >  StrToInt(List[i])then
      begin
        tempString := List[j];
        List[j] := List[i];
        List[i] := tempString
      end;
end;

//Aufruf ereignisgesteuert (z.Bsp. beim Hinzufügen eines Items)mit z.Bsp:
ListIntegerSort(ListBox1.Items);

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
chukalv
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 44



BeitragVerfasst: Do 22.12.05 14:32 
Titel: and anoter way to do that..
If Your list is not large then this kind of sorting (Selectionsort) does it faster:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure ListIntegerSort (List : TStrings);
var
    i, j, best, best2 : integer;
begin
    for i := 0 to List.Count -1 do
    begin
        best := StrToInt(List[i]);
        best2 := i;
        for j := i + 1 to List.Count -1 do
        begin
            if (StrToInt(List[j]) < best) Then
            begin
                best := StrToInt(List[j]);
                best2 := j;
            end;
        end;
        List[best2] := List[i];
        List[i] := inttostr(best);
    end;
end;

_________________
Rihards Gravis
From error to error one discovers the entire truth. /Sigmund Freud/
minipliman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: So 08.01.06 13:33 
bei mir kommt bei beiden versionen die fehlermeldung "class does not have a dafault property"
faux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36

Win XP Pro
C# (VS 2005), Delphi 7
BeitragVerfasst: So 08.01.06 13:41 
user profile iconminipliman hat folgendes geschrieben:
bei mir kommt bei beiden versionen die fehlermeldung "class does not have a dafault property"

Und zwar in welcher Zeile? ;)
minipliman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: So 08.01.06 14:16 
leute danke es funzt, ich muss vorhin irgendwas falsch bei den variableln geändert haben jetzt gehts danke!!!!