Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting same word in an edit and a listbox?

Posted on 2004-10-21
11
Medium Priority
?
176 Views
Last Modified: 2010-04-05
If the same word appears in both an edit and a listbox, I need the wording in the listbox to be shown in a label.  Note that other words will be listed as well, ie:

Example wording in edit: "Do you want elephant.gif?"

Example wording in listbox:
animal/lion.gif
insect/fly.jpg
animal/elephant gif
animal/dog

In the above example, I want "animal/elephant.gif" as a label.

I am using Delphi 6.  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
  • 5
  • 5
11 Comments
 
LVL 12

Accepted Solution

by:
esoftbg earned 2000 total points
ID: 12374393
procedure TForm1.Button1Click(Sender: TObject);
var
  I:      Integer;
  J:      Integer;
  SL:     TStringList;
  S:      string;
  T:      string;
begin
  SL := TStringList.Create;
  try
    T := '';
    S := Trim(Edit1.Text);
    if (S<>'') then
      Label1.Caption := '';
    for I := 1 to Length(S) do
    begin
      if (S[I] in [#33..#62, #64..#126]) then
        T := T + S[I]
      else
      begin
        if (T<>'') then
        begin
          SL.Add(T);
          T := '';
        end;
      end;
    end;
    for I := 0 to ListBox1.Items.Count-1 do
    begin
      for J := 0 to SL.Count-1 do
      begin
        if (Pos(SL[J], ListBox1.Items[I]) > 0) then
        begin
          Label1.Caption := ListBox1.Items[I];
          Break;
        end;
      end;
    end;
  finally
    SL.Free;
  end;
end;
0
 

Expert Comment

by:krypto2000
ID: 12379032
uses strUtils;

procedure split(const Delimiter: Char; Input: string; const Strings: TStrings);
begin
   Assert(Assigned(Strings));
   Strings.Clear;
   Strings.Delimiter := Delimiter;
   Strings.DelimitedText := Input;
end;

procedure TForm1.Button1Click(Sender: TObject);
var splitWords: TStringList; i,j: integer;
begin
   splitWords := TStringList.Create;
   split(#32,edit1.Text,splitWords);

   for i := 0 to listBox1.Items.Count - 1 do
      for j := 0 to splitWords.Count - 1 do
         if ansiContainsStr(listBox1.Items[i],splitWords[j]) then
            label1.Caption := listBox1.Items[i];
end;

That work ;-)
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12379766
download a super example from:
page:        http://www.geocities.com/esoftbg/
  link:        Q_21177707.zip
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:krypto2000
ID: 12380470
okay but this example is to much complicated,
it don't use many powerfull function included in delphi,
it's a old-school-pascal style, for something it's most powerfull to make function like this
but not in this case. I've make some test, the execution time is the same, but I think my solution is better
because it's the half of code, simple to understand, powerfull and working !

thank you
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12381001
Hi krypto2000,

I did improve my example a little bit and then I implement your example into my example to test both ....
I was surprised that yours one does not work at all ????
Please download my example again to see where you have a mistake, so to correct it ....

thank you very much
0
 

Expert Comment

by:krypto2000
ID: 12381044
okay I would check for corrections... :-)
0
 

Expert Comment

by:krypto2000
ID: 12381635
I've found where is the problem.

That's because the text delimiter is the char #32 (space)
but there is no space between the last word and the ?
if you add a space between, that work !
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12381716
You see that sometimes "an old-school-pascal style" can work better than "code, simple to understand, powerfull .... !"
0
 

Expert Comment

by:krypto2000
ID: 12381948
I dont'd hope... because I've see the question "If the same WORD appears in both an edit and a listbox..."
what define a word ? after each space its another word correct ?
But it's also possible to make the same as you with delphi powerfull functions, I'm sure !

Your code is correct, my code too ! Each one its preferences ;-)
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12382542
Your code works with only one delimiter,
my code works with [' ', '*'..'.', ':'..'?']      (count of 11 delimiters)
at a pass and could be easyly changed by programmer to another set ....
0
 

Author Comment

by:rincewind666
ID: 12383180
I am giving the 500 points to esoftbg as his code does exactly what I asked for.  However, I made a mistake in my question and need something similar.  My mistake so I am awarding the points and closing this question.

I have opened another question called "Getting same sequence of characters in an edit and a listbox?".  Another 500 points for anyone who can help.  Thanks.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

604 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