Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

listbox action

Posted on 2001-07-28
7
Medium Priority
?
252 Views
Last Modified: 2010-04-06
I would like to know how to read every line from a listbox and then doing something. For example, the listbox has the full path names of files...and then the user clicks a button and these files in the listbox is deleted.
0
Comment
Question by:marinedestroyer2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6329593
You could do it like this:

To use it just put a ListBox and Button component on a form and put the following code under the Button's OnClick event.

procedure TForm1.Button1Click(Sender: TObject);
var
  I : Integer;
begin
  if ListBox1.Items.Count > 0 then
  begin
    for I := 0 to ListBox1.Items.Count - 1 do
    begin
      if FileExists(ListBox1.Items[I]) = True then
        DeleteFile(ListBox1.Items[I])
      else
        ShowMessage('File does not exist.');
    end;
  end
  else
    ShowMessage('No files listed.');
end;

Cheers,

Alan
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6329595
Hello

  if you want to delete every file in the list box by click on it, just add this code in onclick event

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  DeleteFile(ListBox1.Items.Strings[ListBox1.ItemIndex]);
end;

but if you want to select some items then to delete them i on click, set the MulitSelect for Listbox to true, and add button and write this code

procedure TForm1.Button1Click(Sender: TObject);
  var
    I : integer;
begin
  for I := 0 to ListBox1.Items.Count -1 do
    if ListBox1.Selected[I] then
      DeleteFile(ListBox1.Items.Strings[I]);

end;
Mohammed
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6329610
hi , marinedestroyer2

i had written your answer at the end of your last question.

hamed
0
Technology Partners: 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 1

Expert Comment

by:h_mohsenian
ID: 6329611
if it is related your last question!
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 400 total points
ID: 6329615
Here is an improved version of my example:

procedure TForm1.Button1Click(Sender: TObject);
var
  I : Integer;
begin
  if ListBox1.Items.Count > 0 then
  begin
    I := 0;
    while I <> ListBox1.Items.Count do
    begin
      if FileExists(ListBox1.Items[I]) = True then
      begin
        if DeleteFile(ListBox1.Items[I]) = False then
          ShowMessage('File "' + ListBox1.Items[I] + '" could not be deleted.')
        else
        begin
          ListBox1.Items.Delete(I);
          Dec(I);
        end;
      end
      else
        ShowMessage('File "' + ListBox1.Items[I] + '" does not exist.');
      Inc(I);
    end;
    if ListBox1.Items.Count = 0 then
      ShowMessage('All files deleted succesfully.');
  end
  else
    ShowMessage('No files listed.');
end;
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8734953
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept alanwhincup's comment as answer

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

609 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