Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   buscar en un TMemo (https://www.clubdelphi.com/foros/showthread.php?t=23984)

aranel 04-08-2005 10:31:07

buscar en un TMemo
 
Hola, estoy realizando una aplicación en delphi 5, y en una de las partes tengo que realizar una editor de textos, que disponga de la funcionalidad buscar. Esto lo he encontrado echo en muchos sitios pero a mi realmetne no me funciona :( el codigo que he utilizado a sido:

procedure TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt; //defino la variable donde se ha encontrado
StartPos, ToEnd: Integer; // defino la variable de comienzo y de final
begin

with Memo1 do // cogemos el memo para trabajar con él, todas las variables que cojamos hacen referencia a ese objeto
begin
if SelLength <> 0 then // si no estamos al principio del texto
StartPos := SelStart + SelLength //comenzamos desde donde estemos
else
StartPos := 0;

ToEnd := Length(Text) - StartPos; // definimos la longitud desde el comienzo hasta el final

//EL ERROR ESTÁ EN LA SIGUIENTE LINEA, LA HE COMENTADO PARA PODER COMPILAR
//FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd,[stMatchCase]); // buscamos el texto con los datos que hemso calculado

if FoundAt <> -1 then begin
SetFocus; // colocamos el curso ahí
SelStart := FoundAt; // comenzamos a seleccionar donde lo ha encontrado
SelLength := Length(FindDialog1.FindText); // seleccionamos la longitud del texto a buscar

end;

end;
end;

--------

El error que me da es que dice que no está definida la función FindText. A ver, que me decis, por que yo ya estoy harta de darle vueltas al codigo y no encuentro la solución por ningun lado :confused:

Lepe 04-08-2005 11:00:46

FindText existe en la api de windows, y en el TCustomRichEdit, en el Memo no.

Desde luego, lo más facil es cambiar el memo por un RichEdit, y ahora usar la linea que no compila

Por cierto, ese código es primo-hermano del que viene en la ayuda de delphi para "Position, Execute, FindText, OnFind, SelStart, SelLength example"
Código Delphi [-]
procedure TForm1.FindDialog1Find(Sender: TObject);
var
  FoundAt: LongInt;
  StartPos, ToEnd: Integer;
begin
  with RichEdit1 do
  begin
    { begin the search after the current selection if there is one }
    { otherwise, begin at the start of the text }
    if SelLength <> 0 then

      StartPos := SelStart + SelLength
    else

      StartPos := 0;

    { ToEnd is the length from StartPos to the end of the text in the rich edit control }

    ToEnd := Length(Text) - StartPos;

    FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
    if FoundAt <> -1 then
    begin
      SetFocus;
      SelStart := FoundAt;
      SelLength := Length(FindDialog1.FindText);
    end;
  end;
end;

aranel 04-08-2005 17:33:48

Gracias, cambiaré eso a ver si ya me funciona y si, yo tb me di cuenta despues, que el codigo venia practicamente igual en la ayuda del delphi.

un beso!


La franja horaria es GMT +2. Ahora son las 22:03:53.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi