Autor Beitrag
orakel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 92

Win XP

BeitragVerfasst: Do 08.04.04 17:50 
Hi,
ich möchte eine StringGrid sortieren.
Jetzt kann es aber sein, dass in der ASpalte, nach der sortiert werden soll, entweder Zahlen oder Strings stehen.
Das mit den Strings klappt mit meinem Code schon, aber bei den Zahlen, macht er es dann genause, wie bei den Strings, dass er zuerst nach der 1. Ziffer sortiert und dann nach der 2..
Aber dann kommt natürlich z.B. 18 vor 2 !

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
var pause:string;
    i,j:integer;
begin
 For j:=1 to StringGrid1.RowCount-2   do
 begin
  For i:=1 to StringGrid1.RowCount-2 do
  begin
   If StringGrid1.Cells[0,i]>StringGrid1.Cells[0,i+1] then
   begin
    pause:=StringGrid1.Cells[0,i];
    StringGrid1.Cells[0,i]:=StringGrid1.Cells[0,i+1];
    StringGrid1.Cells[0,i+1]:=pause;
   end;
  end;
 end;
end;


Hat jemand einen Tipp für mich?

Andi

_________________
Nicht verzagen, orakel fragen!
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 08.04.04 17:53 
Hallo

den Zelleninhalt in eine Zahl wandeln und die vergleichen? Macht die sache natürlich langsamer. Aufpassen mußt du noch, daß der Zellinhalt wirklich ein Zahl ist, da gibts mehrere Anregungen im Forum, z.B. Suche in: Delphi-Forum, Delphi-Library VAL.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)