Thema: Delphi Stringgrid sortieren

Einzelnen Beitrag anzeigen

bl3nder

Registriert seit: 18. Aug 2006
89 Beiträge
 
#8

Re: Stringgrid sortieren

  Alt 28. Aug 2008, 13:18
Zitat von Hawkeye219:
Hallo bl3nder,

ich kann verstehen, dass du den Fehler aufdecken möchtest. Nur so kannst du verhindern, dass er dir in Zukunft noch einmal passiert.

Hast du in der Unit eine Variable mit Namen Copy vereinbart? Das würde die Fehlermeldung erklären.

Gruß Hawkeye
Vielen Dank, daran lags !!!

Eine Frage habe ich noch, ist zwar Off Topic aber es gibt dazu schon zu viele Threads, ich checks trotzdem nicht.

Mein Code sieht jetzt so aus:

Delphi-Quellcode:
// sort descending
function TForm1.StringListSortCompare(List: TStringList; Index1, Index2: Integer): Integer;
begin
  Result := AnsiCompareText(List[Index2], List[Index1]);
end;


procedure TForm1.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 - 1) do
        MyList.Add(GenStrGrid.Rows[I].Strings[ThatCol] + TheSeparator +
          GenStrGrid.Rows[I].Text);
      //Sort the List












      Mylist.CustomSort(StringListSortCompare); // [Pascal Fehler] Search.pas(762): E2009 Inkompatible Typen: 'Reguläre Prozedur und Methodenzeiger'












      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 - 1) do
        GenStrGrid.Rows[J].Text := MyList.Strings[(J - 1)];
    end;
  finally
    //Free the List
    MyList.Free;
  end;
end;


procedure TForm1.GridMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
Var
  i,breite,spalte:Integer;
begin
if y<=Grid.RowHeights[0] then
begin
  breite:=0;
  For i:=0 To Grid.ColCount-1 Do
  Begin
    breite:=breite+Grid.ColWidths[i];
    if breite>x Then
    Begin
      spalte:=i;
      Break;
    end;
  end;
  SortStringGrid(Grid, spalte);
end;
end;

In allen Beispielen die ich finde wurde auch so eine komische Funktion geschrieben, die einen Integer zurückliefert.
Wenn ich nun der CustomSort Funktion statisch eine "1" verpasse dann meckert er
Zitat:
[Pascal Fehler] Search.pas(762): E2010 Inkompatible Typen: 'TStringListSortCompare' und 'Integer'
. Was ich widerrum nicht ganz verstehe, weil die Funktion

TForm1.StringListSortCompare(List: TStringList; Index1, Index2: Integer): Integer;

Ja auch eine Integer zurückliefert..

Auch in allen Beispielen.
  Mit Zitat antworten Zitat