Solved

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

Posted on 2006-10-23
7
289 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
Independent Software Vendors: 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

623 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