Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.09.01;
Скачать: CL | DM;

Вниз

Отсортировать по TDateTime   Найти похожие ветки 

 
Jacob   (2003-08-19 02:40) [0]

Что-то у меня толком не получается осуществить сабж.

Нужно отсортировать ЛистВью по столбцу, который заполнен такими значениями:

15.08.03 3:25:45
14.08.03 16:45:50
13.08.03 21:46:14

Делаю кастомсортировку (по возрастанию) и в принципе сортирует нормально, но иногда 13.08.03 21:46:14 идет после 14.08.03 16:45:50 :(((

Где тут грабли???

Кодинг такой:

function CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer;
stdcall;
begin
Result := Trunc(StrToDateTime(Item1.Caption) -
StrToDateTime(Item2.Caption));
end;


 
Романов Р.В. ©   (2003-08-19 06:11) [1]

Если разница меньше суток, то результат равен 0. Как в этом случае будет работать алгоритм?


 
MBo ©   (2003-08-19 06:37) [2]

trunc убери


 
Jacob   (2003-08-19 09:54) [3]

Как убрать? Ведь Integer и Extended!

ListView1.CustomSort(@CustomSortProc, 0)

type TLVCompare = function(lParam1, lParam2, lParamSort: Integer): Integer stdcall;
function CustomSort(SortProc: TLVCompare; lParam: Longint): Boolean;


 
Song ©   (2003-08-19 09:57) [4]

Сравнением напиши.


 
Jacob   (2003-08-19 10:04) [5]

Как? Вот это разве не сравнение:

function CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer;
stdcall;
begin
Result := Trunc(StrToDateTime(Item1.Caption) -
StrToDateTime(Item2.Caption));
end;


 
Jacob   (2003-08-19 10:29) [6]

Как???


 
BillyJeans ©   (2003-08-19 10:30) [7]

function CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer;
stdcall;
begin
Result := Trunc(StrToDateTime(Item1.Caption) >
StrToDateTime(Item2.Caption));
end;


 
Jacob   (2003-08-19 10:32) [8]


> BillyJeans © (19.08.03 10:30) [7]


Это типа шутка?


 
BillyJeans ©   (2003-08-19 10:47) [9]

function CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer; stdcall;
begin
Result := CompareText(DateTimeToStr(Item1.Caption),
DateTimeToStr(Item2.Caption));
end;


 
Jacob   (2003-08-19 14:21) [10]

Этот код не катит.

20.03.03 идет поже, чем 19.07.2003, что не есть гуд.


 
Song ©   (2003-08-19 14:24) [11]

IF StrToDateTime(Item1.Caption)>StrToDateTime(Item2.Caption) then Result:=1 else IF StrToDateTime(Item1.Caption)<StrToDateTime(Item2.Caption) then Result:=-1 else Result:=0;


 
Camus ©   (2003-08-19 14:30) [12]

function CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer; stdcall;
var
D1, D2: TDateTime;
begin
D1 := StrToDateTime(Item1.Caption);
D2 := StrToDateTime(Item2.Caption);
if D1 > D2 then Result := 1 else
if D1 < D2 then Result := -1 else
Result := 0
end;


 
Song ©   (2003-08-19 14:32) [13]

:)


 
Jacob   (2003-08-19 14:40) [14]

У умных людей мысли сходятся.

Спасибо усем.



Страницы: 1 вся ветка

Текущий архив: 2003.09.01;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.021 c
1-1504
Franzy
2003-08-17 12:37
2003.09.01
Глюки с decimal separator ом


14-1665
AGAMEMNUM
2003-08-12 12:45
2003.09.01
имаджлист


6-1543
MegaVolt
2003-06-26 15:44
2003.09.01
Как получить доступ к компутеру с паролем?


3-1293
Amid
2003-07-24 16:07
2003.09.01
Что лучше ADO или DBExpress ?


14-1580
Ajax
2003-08-09 12:15
2003.09.01
Новый сайт и программа