[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Find Text in a Memo / listbox and see if a word is found and then see if that same word is in another memo / listbox??

Posted on 2003-11-15
3
Medium Priority
?
564 Views
Last Modified: 2010-04-05
Hi,

Problem

on a form1 i have:

1 Button / 2 Memo's / 1 x label

In Memo1 i want to have the following:

Jack
And
Jill
Went
Up
The
Hill
To
Fetch


I want the user to type content into Memo 2 (and this content will be anycase (not case sensitive) i.e

HEllO mY naME iS ANdRew SHanKLIN  etc....

I want the user to click button 1 and a message box to pop up and:

If found: 'One of these words in memo 1 has been found in memo2 on Line Number 1 etc...' or if possible specify which word has been found in memo1 is inmemo2

If Not Found then Label1.caption := 0

So to sumarize...


User enters content clicks button 1 if a word in memo1 is found in memo2 then show message and show line number (Show found word if possible) and if no memo1 words are found in memo2 then label1.caption := 0

Please dont write any exceptions into the code.

Plese provide me with some full source etc...

ie:

procedure TForm1.Button1Click(Sender: TObject);
var
 i: Integer;

begin


Please "spell it out for me" as i am quite new to Delphi

Thanks in advance.

Andy
0
Comment
Question by:AndrewShanklin
[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
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
gmayo earned 1160 total points
ID: 9753647
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
      i : integer;
begin
      for i := 0 to Memo1.Lines.Count - 1 do begin
            if Pos(LowerCase(Memo1.Lines[i]), LowerCase(Memo2.Text)) > 0 then begin
                  ShowMessage('"' + Memo1.Lines[i] + '" found on line ' + IntToStr(i + 1));
            end;
      end;
end;

end.


Basically, it goes through each line of memo1 (which I assume contains one word per line) and then looks for that word in memo2's text property. If found, it then displays that word with the line number from memo1.

Geoff M.
0
 

Author Comment

by:AndrewShanklin
ID: 9754164
gmayo

Your code works great however i need the message to show that the word "Jack" in Memo 1 has been found in Memo 2 and to state the line jack is on in memo2 not the line its on in memo1.

Hope that makes sense.


Please help.

Thanks.

Andy
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9754247
I thought that might be the case. Here's an amended example:

procedure TForm1.Button1Click(Sender: TObject);
var
      i, wordpos : integer;
      LineNumber : integer;
begin
      for i := 0 to Memo1.Lines.Count - 1 do begin
            wordpos := Pos(LowerCase(Memo1.Lines[i]), LowerCase(Memo2.Text));
            if wordpos > 0 then begin
                  LineNumber := SendMessage(Memo2.Handle, EM_LINEFROMCHAR, wordpos, 0);
                  ShowMessage('"' + Memo1.Lines[i] + '" found on line ' + IntToStr(LineNumber + 1));
            end;
      end;
end;


Geoff M.
0

Featured Post

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!

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

649 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