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

Вниз

Sorting TList   Найти похожие ветки 

 
McSimm2   (2003-12-04 11:13) [0]

Можно отсортировать данные в TListe по 2 полям ?


 
Digitman ©   (2003-12-04 11:20) [1]

да хоть по 20-ти


 
Anatoly Podgoretsky ©   (2003-12-04 11:26) [2]

Только в TList нет 2 полей, это всего список указателей.


 
McSimm2   (2003-12-04 11:34) [3]

Anatoly Podgoretsky © (04.12.03 11:26) [2]
Да, точно, конечно же...

Подскажите, плиз, как сделать сортировку по 2 полям.



PReportRecord = ^TReportRecord;
TReportRecord = record
Month, Year: String;
....
end;

procedure TFrm_main.SortList();

function CompareListItems(Item1, Item2: Pointer): Integer;
var
RecA: PReportRecord absolute Item1;
RecB: PReportRecord absolute Item2;
begin
if RecA^.Year < RecB^.Year then
Result := -1 else
if RecA^.Year = RecB^.Year then
Result := 0 else
Result := 1;
end;

begin
FReportList.Sort(@CompareListItems);
end;


Как сделать что бы отсортировалось по году(1) и по месяцу(2) ???


 
Семен Сорокин ©   (2003-12-04 11:38) [4]

наверное так:

function CompareListItems(Item1, Item2: Pointer): Integer;
var
RecA: PReportRecord absolute Item1;
RecB: PReportRecord absolute Item2;
begin
if RecA^.Year < RecB^.Year then
Result := -1
else if RecA^.Year > RecB^.Year then
Result := 1
else if RecA^.Month < RecB^.Month then
Result := -1
else if RecA^.Month > RecB^.Month then
Result := 1
else
Result := 0
end;


 
gek ©   (2003-12-04 11:39) [5]

Попробуй так

if RecA^.Year < RecB^.Year then
begin
if RecA^.Month < RecB^.Month then
....
end


 
McSimm2   (2003-12-04 11:42) [6]

Семен Сорокин © (04.12.03 11:38) [4]
Большое спасибо - всё OK

Всем спасибо!



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

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

Наверх




Память: 0.47 MB
Время: 0.012 c
3-52095
GIL
2003-11-24 13:22
2003.12.16
Имена полей в SQL


14-52397
Ломброзо
2003-11-21 10:15
2003.12.16
Ё-моё, с Днем Рож#дения!


14-52377
Думкин
2003-11-24 05:41
2003.12.16
С днем рождения! 24 ноября.


14-52374
Дон Хуан
2003-11-03 12:42
2003.12.16
---|Ветка была без названия|---


3-52106
Vanek
2003-11-24 10:30
2003.12.16
По интерфейсу