Solved

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

Posted on 2006-10-23
7
287 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
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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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