Solved

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

Posted on 2006-10-23
7
284 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
Comment Utility
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:ciuly
Comment Utility
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
Comment Utility
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
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

 
LVL 19

Expert Comment

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

Expert Comment

by:ciuly
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

14 Experts available now in Live!

Get 1:1 Help Now