Solved

Listing items in listbox without certain extensions

Posted on 2004-10-19
4
280 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

809 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