?
Solved

Listing items in listbox without certain extensions

Posted on 2004-10-19
4
Medium Priority
?
284 Views
Last Modified: 2010-04-05
I have a list of items in a listbox.  I now want to list these same items in a second listbox but without files with extensions of ".gif" and ".jpg". I have tried the following code but it doesn't work.  Why?  I am using Delphi 6.  Many thanks for your help.

i := 0;
repeat
begin

if (ExtractFileExt(ListBox1.Items.Strings[i]) <> '.gif') or (ExtractFileExt(ListBox1.Items.Strings[i]) <> '.jpg) then
ListBox2.Items.Add(ListBox1.Items.Strings[i];

end;
inc(i);
until i = ListBox1.Items.Count;    
0
Comment
Question by:rincewind666
[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
  • 2
4 Comments
 
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 1000 total points
ID: 12350069
(ExtractFileExt(ListBox1.Items.Strings[i]) <> '.gif') or (ExtractFileExt(ListBox1.Items.Strings[i]) <> '.jpg)

This evaluates to true all the time... :-)

(ExtractFileExt(ListBox1.Items.Strings[i]) <> '.gif') AND (ExtractFileExt(ListBox1.Items.Strings[i]) <> '.jpg)

AND
AND
AND
AND
AND

But better:
not (AnsiCompareText(ListBox1.Items.Strings[i], '.gif') or AnsiCompareText(ListBox1.Items.Strings[i], '.jpg'))

Add the if-then yourself, please...
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12350081
Oh, and in my last code, it must be OR, not AND...
0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 1000 total points
ID: 12350140
You may be able to speed the process up a little bit, and make it more reable with something  like:

var
  E:string;

i := 0;
repeat
  begin
    E:=lowercase(ExtractFileExt(ListBox1.Items.Strings[I]);
    if (E<>'.gif') and (E<>'.jpg')    //easy to add more tests here...
    then
      ListBox2.Items.Add(ListBox1.Items.Strings[i];
  end;
  inc(i);
until i = ListBox1.Items.Count;    
0
 

Author Comment

by:rincewind666
ID: 12350648
Many thanks for your help. Greatly appreciated.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 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