![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
удаление повторяющихся строк [D6]
Chipik © (2005-08-14 05:44:00)Уже месяц сижу, не получается. Надобно дубликаты удалить из ListBox'а, а то как-то неудобно, да и информации лишней много. Помогите, пожалуйста. Заранее благодарен.
begin...end (2005-08-14 09:25:00) [1]> 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, вместо того чтобы потом удалять их из него.
Defunct (2005-08-14 08:10:00) [2]
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;