Solved

Listing items in listbox without certain extensions

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now