Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copying known file names if mentioned in memo (500 points)

Posted on 2006-10-23
7
Medium Priority
?
291 Views
Last Modified: 2010-04-05
I have a list of file names in a combobox.

If any of these file names are mentioned in a memo, I want that file name to be copied to a second combobox.

It must be copied just ONCE in case the same file name is mentioned several times in the memo.

I want to use the second combobox to search for the file name in the memo later (I have the code for searching).

I am using Delphi 6.  I am awarding 500 points as this is required URGENTLY.  Many thanks for your help.
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
7 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 17791546
ComboBox1 has list of files
ComboBox2 is destination

var i: integer;
begin
 for i := 0 to ComboBox1.Items.Count - 1 do                       // go through all items in combobox1
  if (Memo1.Lines.IndexOf(ComboBox1.Items[i]) <> -1) and          // is it found in the memo?
     (ComboBox2.Items.IndexOf(ComboBox1.Items[i]) = -1) then      // is it not found in ComboBox2?
   ComboBox2.Items.Add(ComboBox1.Items[i]);                       // add it
end;
0
 
LVL 28

Expert Comment

by:2266180
ID: 17791576
replace
if (Memo1.Lines.IndexOf(ComboBox1.Items[i]) <> -1)
with
if pos(ComboBox1.Items[i], memo1.lines.text)>0

because that indexof will search for a sting that is equal to a full line from a memo ;)
0
 
LVL 3

Expert Comment

by:cobi100
ID: 17791584
try using this code:

procedure TForm1.Button1Click(Sender: TObject);
var
  i,j: integer;
begin
  for i := 0 to ComboBox1.Items.Count - 1 do
    for j := 0 to Memo1.Lines.Count - 1 do
      if AnsiContainsText(Memo1.Lines[j], ComboBox1.Items[i]) then
      begin
        ComboBox2.Items.Add(ComboBox1.Items[i]);
        Break;
      end;
end;

BTW, make sure StrUtils is included in the uses clause
0
Industry Leaders: 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 19

Expert Comment

by:MerijnB
ID: 17791890
@ciuly: isn't that what he wants?
0
 
LVL 28

Expert Comment

by:2266180
ID: 17792186
dunno. when I read: "If any of these file names are mentioned in a memo" I first think that it can appear anywhere. that is, the memo is not a list, but some text. but you might be right :)
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 2000 total points
ID: 17794056
well, if the filenames can appear anywhere in the memo, this little tweak might be a very good optimizer when the lists grow:

var i: integer;
    s: string;
begin
 s := Memo1.Lines.Text;
 for i := 0 to ComboBox1.Items.Count - 1 do                       // go through all items in combobox1
  if (Pos(ComboBox1.Items[i], s) > 0) and          // is it found in the memo?
     (ComboBox2.Items.IndexOf(ComboBox1.Items[i]) = -1) then      // is it not found in ComboBox2?
   ComboBox2.Items.Add(ComboBox1.Items[i]);                       // add it
end;
0
 

Author Comment

by:rincewind666
ID: 17794206
Yes, the filename can appear anywhere, whence the memo instead of a listbox.

I am giving the points to MerijnB, as he gave the first response to this urgent problem.  I also give him and the others my grateful thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

719 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