Вниз
Скачать: CL | DM;

Сортировка в ComboBox   Найти похожие ветки 

 
Кос   (2012-06-23 15:44) [0]

функция сортировки по дате

function CompareDates(List: TStringList; Index1, Index2: Integer): Integer;
var
  d1, d2: TDateTime;
begin
 d1 := StrToDateTime(List[Index1]);
 d2 := StrToDateTime(List[Index2]);
 if d2 < d1 then
    Result := -1
 else if d2 > d1 then Result := 1
 else
    Result := 0;
end;


FindRes := FindFirst("F:\1\*.*", faAnyFile, SR);
 while FindRes = 0 do
 begin
   if (SR.Name <> ".") and (SR.Name <> "..") then
     begin
       ListBox1.Items.Add(DateTimeToStr(FileDateToDateTime(SR.time))+"  "+SR.Name);
       ComboBox1.Items.Add(SR.Name);
       ListBox2.Items.Add(SR.Name);
     end;
       FindRes := FindNext(SR);
 end;
 FindClose(SR);  //Закрываем поиск

sl:=TStringList.Create;
try
  sl.Assign(listbox1.Items);
  sl.CustomSort(CompareDates);
  listbox1.Items.Assign(sl);
finally
  sl.Free
end;

В ListBox1 складываю для наглядности файлы со временем их создания и названием и сортирую их по дате, примерно такой вид 01.01.12 00:11:22 12312455 (дата_время_название файла)
В ComboBox1 и ListBox2 просто названия.
Вопрос как мне теперь отсортированные названия файлов (из ListBox1) в ComboBox1 отправить, поскольку дальше я по названию файла загружаю их в StringGrid.


 
AV ©   (2012-06-23 17:49) [1]

var
 sl: TStringList;
begin
 ComboBox1.Items.Add("aaaa");
 ComboBox1.Items.Add("cccc");
 ComboBox1.Items.Add("dddd");
 ComboBox1.Items.Add("bbbb");
 sl := TStringList.Create;
 sl.Assign(ComboBox1.Items);
 sl.Sort;
 ComboBox1.Clear;
 ComboBox1.Items.Assign(sl);
 FreeAndNil(sl);


 
Inovet ©   (2012-06-23 18:03) [2]

> [1] AV ©   (23.06.12 17:49)

У ТС дата текстом. Но он не позаботился о японцах, американцах и других.



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

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.168 c
2-1329216786
AV
2012-02-14 14:53
2013.03.22
TidTelnet и метод Disconnect;


15-1338256258
Error macro
2012-05-29 05:50
2013.03.22
Как стать фрилансером?


15-1336739016
БарЛог
2012-05-11 16:23
2013.03.22
отличие os от bios


15-1346298363
brother
2012-08-30 07:46
2013.03.22
Помогите с алгоритмом


3-1279402005
belartvlad29
2010-07-18 01:26
2013.03.22
В ячейках DBGrid изображается поле типа text как (Memo)




   Наверх