Autor Beitrag
Jagg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mi 06.07.05 00:10 
Hallo Leute !

Ich habe eine Procedure und einen Stringrid,das ich sortiere :
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:
37:
38:
39:
40:
41:
42:
43:
procedure SortStringGrid(var GenStrGrid: TStringGrid; ThatCol: Integer);
const
  // Define the Separator
  TheSeparator = '@';
var
  CountItem, I, J, K, ThePosition: integer;
  MyList: TStringList;
  MyString, TempString: string;
begin
  // Give the number of rows in the StringGrid
  CountItem := GenStrGrid.RowCount;
  //Create the List
  MyList        := TStringList.Create;
  MyList.Sorted := False;
  try
    begin
      for I := 1 to (CountItem - 1do
        MyList.Add(GenStrGrid.Rows[I].Strings[ThatCol] + TheSeparator +
          GenStrGrid.Rows[I].Text);
      //Sort the List
      Mylist.Sort;
      for K := 1 to Mylist.Count do
      begin
        //Take the String of the line (K – 1)
        MyString := MyList.Strings[(K - 1)];
        //Find the position of the Separator in the String
        ThePosition := Pos(TheSeparator, MyString);
        TempString  := '';
        {Eliminate the Text of the column on which we have sorted the StringGrid}
        TempString := Copy(MyString, (ThePosition + 1), Length(MyString));
        MyList.Strings[(K - 1)] := '';
        MyList.Strings[(K - 1)] := TempString;
      end;

      // Refill the StringGrid
      for J := 1 to (CountItem - 1do
        GenStrGrid.Rows[J].Text := MyList.Strings[(J - 1)];
    end;
  finally
    //Free the List
    MyList.Free;
  end;
end;

Aufruf z.b. : SortStringGrid(sgoffen,1);
....aber wenn in der Spalte das angegeben wird,ein Datum drinne steht,dann sortiert er nicht richtig,kann mir einer sagen warum ?
Hängt es damit zusammen,das ein ein Datumsformat ist ?

Jagg

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 06.07.05 00:45 
Moin!

Du hast mit 640 Beiträgen immer noch nicht gelernt, wozu der Delphi-Tag da ist... ? :gruebel: Abgesehen davon, hattest du in der Schule keinen Deutschunterricht? :wink: Sorry, aber deine Sätze sind schon "interessant" aufgebaut. :shock:

user profile iconJagg hat folgendes geschrieben:
aber wenn in der Spalte das angegeben wird,ein Datum drinne steht,dann sortiert er nicht richtig,kann mir einer sagen warum ?
Hängt es damit zusammen,das ein ein Datumsformat ist ?

Scheint da, wo du den Code "abgeschrieben" hast, wohl nicht dabeigestanden zu haben. :wink: Klar liegt das daran, dass das Datum als Text vorliegt; du mußt in der StringListe eine eigene Sortierprozedur verwenden; wie das geht, ist hier im Forum beschrieben, einfach mal danach suchen.

cu
Narses