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
545 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 290 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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…

695 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