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
536 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

17 Experts available now in Live!

Get 1:1 Help Now