I have a grid with 4 columns of dates (out of a total of 58 columns) all in the format mm/dd/yyyy. Whenever I attempt to sort, the program crashes with a message like Project prog.exe raised exception class EConvertError with message ''09/03/200' is not a valid date and time.' Process stopped.
Ignoring these columns is the only way to be able to sort. Setting the style in
procedure TGrid.AdvStringGrid1GetFormat(Sender: TObject; ACol: Integer;
var AStyle: TSortStyle; var aPrefix, aSuffix: String);
begin
case ACol of
7,8,15,16 : Astyle := ssAlphabetic;
end;
end;
does nothing. I can set it's style as Alphabetic, Date, ShortDateUS, or even raw and I still get the invalid date and time message.
I cannot reproduce a problem here. A default grid initialized with:
It's very strange. I have examined the date strings...no hidden characters or anything. Exports to Excel, CSV, and html all show normal dates. (The error message I quoted should have read '09/03/2009' not '09/03/200' by the way.)
The error takes me to the function TAdvStringGrid.CompareLine(Col,ARow1,ARow2: Integer): Integer; in AdvGrid.pas to the line
res := Compare(Col,ARow1,ARow2,SortSettings.Direction);
Okay the problem is in the way the dates are read and parsed from the original delimited text files. I still don't know what is wrong with the parsed string '09/03/2009' but the original string '20090903' works fine. Oh the joys of updating someone else's old code...