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

Вниз

удаление повторяющихся строк   Найти похожие ветки 

 
Chipik   (2005-08-14 05:44) [0]

Уже месяц сижу, не получается. Надобно дубликаты удалить из ListBox"а, а то как-то неудобно, да и информации лишней много. Помогите, пожалуйста. Заранее благодарен.


 
Defunct ©   (2005-08-14 08:10) [1]

procedure DeleteDublicates( AListBox : TListBox);
var
 i, j : integer;
 CanAdd : boolean;
begin
 SendMessage( AListBox.Handle, WM_SETREDRAW, 0, 0);
 with TStringList.Create do
 try
    for i := 0 to AListBox.Count - 1 do
    begin
       CanAdd := True;
       for j := 0 to Count - 1 do
          if Strings[j] = AListBox.Items[i] then
          begin
            CanAdd := False;
            break;
          end;
       if CanAdd then
          Add( AListBox.Items[i]);
    end;

    AListBox.Items.Text := Text;

 finally
    free;
    SendMessage( AListBox.Handle, WM_SETREDRAW, 1, 0)
 end;
end;


 
begin...end ©   (2005-08-14 09:25) [2]

> Chipik   (14.08.05 05:44)

with ListBox do
begin
 I := Pred(ListBox.Count);
 while I > 0 do
 begin
   for J := I - 1 downto 0 do
     if ListBox.Items[J] = ListBox.Items[I] then
     begin
       Items.Delete(J);
       Dec(I)
     end;
   Dec(I)
 end
end


Если же ListBox можно отсортировать, или он уже отсортирован, то можно и так:

with TStringList.Create do
 try
   Sorted := True;
   Text := ListBox.Items.Text;
   ListBox.Items.Text := Text;
 finally
   Free
 end


Также можно подумать о том, чтобы не добавлять дубликаты в ListBox, вместо того чтобы потом удалять их из него.



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

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

Наверх




Память: 0.47 MB
Время: 0.026 c
14-1125475345
ПЛОВ
2005-08-31 12:02
2005.09.25
Поможите, что значит " /= " в Си


1-1125341627
kblc
2005-08-29 22:53
2005.09.25
Docking в Delphi 2005


1-1125397351
DimaBr
2005-08-30 14:22
2005.09.25
FontDialog


2-1123970686
ArtemESC
2005-08-14 02:04
2005.09.25
CopyFrom класса TStream


14-1125648012
Igorek
2005-09-02 12:00
2005.09.25
Кто пользуется RSS