[Okta Webinar] Learn how to a build a cloud-first strategyRegister 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
?
568 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 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

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…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

873 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