August 27th, 2004, 02:08 AM
Join Date: May 2004
Time spent in forums: < 1 sec
Reputation Power: 0
Deleting selected item in TListView
For some reason, when i try to delete a selected item in the TListView, i get EAccessViolation Error. But the code still deletes the selected item. Here is what i have.
procedure TForm1.Button6Click(Sender: TObject);
with Listview1 do
for i := 0 to Items.Count - 1 do
if Items[i].Selected then
Items.Delete(Items.IndexOf(FindCaption(0, Items[i].Caption, False, True, False)));
except on EAccessViolation do
I had to catch the exception to make it stop showing that error message. But why is it causing it? The code seems to be fine and logical. Any help would be appreciated. Thank you!