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

Удаления дубликатов в ListBox   Найти похожие ветки 

 
Киря   (2003-05-04 17:01) [0]

У меня в Listbox"e перечисляется список имён.
Как по нажатию на кнопку убрать все дублирующиеся имена?


 
Anatoly Podgoretsky ©   (2003-05-04 17:13) [1]

А зачем их туда помещать?


 
vlad40 ©   (2003-05-04 17:27) [2]

Если в ListBox"е у тебя отсортированный список, то можно так:

var list: TStringList;
...
list:=TStringList.Create;
list.Sorted:=True;
list.Assign(ListBox1.Items);
ListBox1.Items.Assign(list);
list.Free;
...


 
circul ©   (2003-05-04 17:29) [3]

function MySort(List: TStringList; Index1, Index2: Integer): Integer;
begin
Result := Integer(List.Objects[Index1]) - Integer(List.Objects[Index2]);
end;

procedure TfTestDll.Button1Click(Sender: TObject);
var
tL: TStringList;
i: Integer;
begin
tL:= TStringList.Create;
tL.Sorted := True;
tL.Duplicates := dupIgnore;
try
for i := 0 to ListBox.Items.Count-1 do
begin
ListBox.Items.Objects[i] := pointer(i);
end;

tL.AddStrings(ListBox.Items);
tL.Sorted := False;

tL.CustomSort(MySort);

ListBox.Items.Clear;
ListBox.Items.Assign(tL);

finally
tL.Free;
end;

end;


 
Юрий Зотов ©   (2003-05-04 17:44) [4]

А если любой, то так:

var
i, j: integer;
...
with ListBox1.Items do
begin
BeginUpdate;
try
for i := Count - 1 downto 1 do
begin
j := IndexOf(Strings[i]);
if (j >=0) and (j < i) then Delete(i)
end
finally
EndUpdate
end
end;



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

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



Память: 0.45 MB
Время: 0.013 c
1-46685
Fast
2003-05-03 16:03
2003.05.15
ListBox прокрутка


1-46726
Loki
2003-05-04 23:07
2003.05.15
TWebBrowser


1-46736
Great DAN
2003-05-05 06:21
2003.05.15
Выделить всю строку в StringGrid


6-46872
Katy
2003-03-18 12:15
2003.05.15
ServerSocket dll MsSql странности...


1-46826
Вова Б
2003-05-02 20:46
2003.05.15
Сравнение строк




   Наверх