Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 04-08-2005
aranel aranel is offline
Miembro
 
Registrado: jul 2005
Posts: 37
Poder: 0
aranel Va por buen camino
Unhappy 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
Responder Con Cita
  #2  
Antiguo 04-08-2005
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Poder: 29
Lepe Va por buen camino
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;
__________________
Si usted entendió mi comentario, contácteme y gustosamente,
se lo volveré a explicar hasta que no lo entienda, Gracias.
Responder Con Cita
  #3  
Antiguo 04-08-2005
aranel aranel is offline
Miembro
 
Registrado: jul 2005
Posts: 37
Poder: 0
aranel Va por buen camino
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!
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 22:28:09.


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
Copyright 1996-2007 Club Delphi