Einzelnen Beitrag anzeigen

schwa226

Registriert seit: 4. Apr 2008
400 Beiträge
 
#9

AW: CSV Textdatei, Zeilen sortieren

  Alt 11. Jul 2012, 11:49
Danke!

Werde es mit dem einfachen Sort noch probieren!

Derweilen habe ich mir eine CustomSort geschrieben:
Delphi-Quellcode:
function CompareDates(List: TStringList; Index1, Index2: Integer): Integer;
var
  d1, d2: TDateTime;
  p1, p2 : Integer;
  FormatSettings: TFormatSettings;
begin
  p1 := Pos(',', List[Index1]) - 1;
  p2 := Pos(',', List[Index2]) - 1;

  if (p1 = 0) or (p2 = 0) then
  begin
    Result := -1;
    Exit;
  end;

  FormatSettings.TwoDigitYearCenturyWindow:=1;
  FormatSettings.DateSeparator:='/';
  FormatSettings.TimeSeparator:=':';
  FormatSettings.ShortTimeFormat:= 'hh:nn';
  FormatSettings.LongTimeFormat:= 'hh:nn:ss';
  FormatSettings.ShortDateFormat:= 'yy.mm.dd';
  FormatSettings.LongDateFormat:= 'yyyy.mm.dd';

  try
    d1 := StrToDateTime(LeftStr(List[Index1], p1), FormatSettings);
    d2 := StrToDateTime(LeftStr(List[Index2], p2), FormatSettings);
  except
    Result := -1;
    Exit;
  end;

  if d1 < d2 then
    Result := -1
  else if d1 > d2 then Result := 1
  else
    Result := 0;
end;
EDIT:
Ja, Sort reicht aus
Delphi 2010, Update 4 & 5

Geändert von schwa226 (11. Jul 2012 um 11:52 Uhr)
  Mit Zitat antworten Zitat