Search TMemo Delphi

1

Good afternoon everyone! I am doing full name search in a TMemo with Delphi, when the whole name is in the same line it works nice, but if part of the name is in one line and the other part in the next line, the search does not find. Any idea to solve this?

procedure TForm1.BitBtn4Click(Sender: TObject); 
var 
  acha:string; 
begin 
  if (Memo1.GetTextLen > 0) then 
  begin 
    zPessoa.First; 

    if not zPessoa.Eof then 
      repeat acha:=zPessoanome.Value; 

    if pos(acha, AnsiUpperCase(memo1.Lines.text))>0 then begin 
    
asked by anonymous 18.06.2018 / 22:17

2 answers

1

You should use Memo.Lines.Text to do so:

  if Pos('Nome', Memo1.Lines.Text) > 0 then
    ShowMessage('Achou')
  else
    ShowMessage('Não achou');

If you need to know the line number:

var
  i: Integer;
begin
  for i := 0 to Memo1.Lines.Count - 1 do
  begin
    if Pos('Nome', Memo1.Lines[i]) > 0 then
      ShowMessage('Texto encontrado na ' +IntToStr(i+1) +'ª linha');
  end;
end;

In your code, the problem is that acha also needs to be UpperCase, otherwise it will always compare, for example, John Smith with JOHN SILVA , which will always make a difference.

if not zPessoa.Eof then    
   repeat acha := AnsiUpperCase(zPessoanome.Value);

After the subject is best explained, your problem can be solved by replacing the line break with space using Replace (StrUtils):

if Pos('Nome', Memo1.Lines.Text.Replace(sLineBreak, ' ')) > 0 then
  ShowMessage('Achou')
    
18.06.2018 / 22:27
0

Good morning everyone! Thanks to those who were interested in helping me! I solved the problem outside the routine, as I needed to copy the text from the official memo pro Memo, before I "dumped" it, I played it in Notepad ++, I turned it into a single line and solved problem!

    
22.06.2018 / 15:13