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
537 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

895 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