shekou
asked on
How to delete multi recorders in Listview?
I want to delete multi recorders in listview at same time, following is
my code:
with mylistview1 do
begin
if items.Count=0 then exit;
for i:= 0 to Items.Count-1 do
if items[i].Selected then Items[i].Delete;
end;
but get error message 'access violation
at address 0047A898', how to solve it?
I am using Delphi 5 and Win98.
Thanks
Shekou
my code:
with mylistview1 do
begin
if items.Count=0 then exit;
for i:= 0 to Items.Count-1 do
if items[i].Selected then Items[i].Delete;
end;
but get error message 'access violation
at address 0047A898', how to solve it?
I am using Delphi 5 and Win98.
Thanks
Shekou
Incidently you dont need this line: if items.Count=0 then exit;
with mylistview1 do
begin
for i:= Items.Count-1 downto 0 do
if items[i].Selected then Items[i].Delete;
end;
Sorry an explanation:
suppose you have 5 items in the list that are all selected.
If you delete item[0] there are now only 4 items in the list.
If you delete item[1] there are now only 3 items in the list.
If you delete item[2] there are now only 2 items in the list.
So when you try to delete item[3], you will get an error because item[3] does not exist.
You need to start with the last item in the list, to stop this.
Regards Aubs
with mylistview1 do
begin
for i:= Items.Count-1 downto 0 do
if items[i].Selected then Items[i].Delete;
end;
Sorry an explanation:
suppose you have 5 items in the list that are all selected.
If you delete item[0] there are now only 4 items in the list.
If you delete item[1] there are now only 3 items in the list.
If you delete item[2] there are now only 2 items in the list.
So when you try to delete item[3], you will get an error because item[3] does not exist.
You need to start with the last item in the list, to stop this.
Regards Aubs
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
don't look at the comments ;)
regards...
regards...
ASKER
Thank you two, both way works.
Thanks
shekou
Thanks
shekou
Hello,
just curious...
why only a B ?, the answer was with
source code and just a cut and paste
to make your problem work.
let me know please so I can enhance
my next answers...
Thanks.
just curious...
why only a B ?, the answer was with
source code and just a cut and paste
to make your problem work.
let me know please so I can enhance
my next answers...
Thanks.
with mylistview1 do
begin
if items.Count=0 then exit;
for i:= Items.Count-1 downto 0 do
if items[i].Selected then Items[i].Delete;
end;