Solved

How to delete multi recorders in Listview?

Posted on 2000-04-07
6
209 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 100 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
proper way to parse url in delphi 2 202
control image tags in a string ? 12 129
Delphi...Split view - idea? 1 68
Sending files from  idTcpServer Socket to idTcpClient 2 40
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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