Solved

Listing items in listbox without certain extensions

Posted on 2004-10-19
4
283 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 250 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 250 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 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