Solved

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

Posted on 2006-10-23
7
285 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 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