Search a string in a TMemo  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 21/08/99

Tip accessed 562 times

 


This example, search the string 'Cadena' in Memo1, and if found it, scroll the Memo and higlight it.


 procedure TForm1.Button2Click(Sender: TObject);
 var
    Posicion:longint;
    Cadena:string;
 begin
  Cadena:='begin';

  {Saber la posición de una cadena en un TMemo}
  {Know the position of the string in the TMemo}
  Posicion:=Pos(Cadena,Memo1.Text)-1;

  {Mover el Cursor (caret) hasta allí}
  {Move the caret}
 {
  with Memo1. do
  begin
    SelStart:=Posicion;
    SelLength:=0;
    SetFocus;
  end;
 }

  {Resaltar la cadena en el TMemo:}
  {HighLight the string searched}
  with Memo1 do
  begin
    SelStart:=Posicion;
    SelLength:=Length(Cadena);
    SetFocus;
  end;
 end;