Research Tmemo Delphi

Asked

Viewed 518 times

1

Good afternoon to you all! I am doing full name search on a Tmemo with Delphi, when the whole name is on the same line works well, but if part of the name is on one line and the other part on the next line, the search does not find. Any idea how 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 
  • How’s your code at the moment?

2 answers

1

The Memo.Lines.Text for such:

  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 acha also needs to be Uppercase, otherwise it will always compare, for example, João Silva with JOÃO SILVA, which will always make a difference.

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

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

if Pos('Nome', Memo1.Lines.Text.Replace(sLineBreak, ' ')) > 0 then
  ShowMessage('Achou')
  • The code is working very well, the problem is that it does not find the name that is in a line break.

  • Type: Marques Leão Magalhães, like you think with or without accent!

  • But: Marques Leão (End of a line) Magalhães (Beginning of the next one).

  • Replace line break by space. I edited my answer with an example.

0

Good morning to you all! I thank those who were interested in helping me! I solved the problem out of routine, as I needed to copy the text of the official journal pro Memo, before "dump it" there, game on Notepad++, turn into a single line and solved problem!

  • I’m glad you did. But for the purpose of helping the next people who have a similar problem, could you tell me whether or not my answer worked for you? I had proposed replacing the line break by a space, which would have the same effect as you ran out of routine.

  • Thanks Cleber Griff! It did not work, inclusive, I found that when this situation occurs within Word, with the search itself, does not work...

  • Nor with the .Replace(sLineBreak, ' ') ? I was curious rs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.