Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Text in Memo? 1

Status
Not open for further replies.

ug505

Programmer
Jan 2, 2010
52
US
Hello all,

I'm trying to make my own configuration file so that other people can change it and make it in their own way. (changing color, captions, etc.) I know how to load a file into a Memo, but I don't know how to find specific text in it. Can anyone help me? I use Delphi 7 by the way.
 
The text in a memo is stored in the lines object. This can be treated like a TStringList. So if you wanted to find out which lines of the memo contained a specific string you could do something like:
Code:
var
  lineNumber: integer;
begin
  for lineNumber := 0 to memo.lines.count-1 do
    if Pos( 'target', memo.lines[lineNumber] ) > 0 then
      ShowMessage( 'Found in line ' + IntToStr(lineNumber) );
end;
You can also access the whole of the memo contents using the Text object. So, for example, if you wanted to see if a memo contained a particular string then you could code something like
Code:
begin
  if Pos( 'target', memo.lines.Text ) > 0 then
    ShowMessage( 'Found target in memo' )
  else
    ShowMessage( 'Target not found in memo' );
end;

Andrew
Hampshire, UK
 
Thank you very much! Your post helped me a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top