Главная страница
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.015 c
3-1314
gsvserg
2003-08-08 15:25
2003.09.01
Возможно ли сделать такой запрос?


3-1345
Buka
2003-08-05 13:24
2003.09.01
Перенос данных из Excel в Table


3-1273
dimm
2003-08-11 17:22
2003.09.01
DBLookupCombobox не открывается полностью. Т.е. хочу видеть все


14-1655
Knight
2003-08-12 10:02
2003.09.01
Все упали ниц.... перед супер-пупер програмером... :))))))


14-1674
likeanangel
2003-08-12 11:22
2003.09.01
Поддержка XML API