Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to delete multi recorders in Listview?

Posted on 2000-04-07
6
Medium Priority
?
235 Views
Last Modified: 2010-04-04
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

0
Comment
Question by:shekou
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:aubs
ID: 2693069
try doing it backwards
 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;
0
 
LVL 2

Expert Comment

by:aubs
ID: 2693100
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
0
 
LVL 4

Accepted Solution

by:
jeurk earned 300 total points
ID: 2693112
hello you should it like that :

procedure TForm1.Button3Click(Sender: TObject);
var
  liSelected, liBuffer: TListItem; //the item actualy selected in the listview
begin
  liSelected := mylistview1.Selected;
  if liSelected = nil then
    exit; //shoul not be possible

  while mylistview1.SelCount <> 0 do
  begin
    //delete the selected Items because they no longer exists
    liBuffer := liSelected;
    //get the next selevted item
    liSelected := mylistview1.GetNextItem(liSelected, sdAll, [isSelected]);
    liBuffer.Delete;
  end;
end;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:jeurk
ID: 2693115
don't look at the comments ;)
regards...
0
 

Author Comment

by:shekou
ID: 2695841
Thank you two, both way works.

Thanks

shekou
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2699524
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question