Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 07-02-2005
Arkaz Arkaz is offline
Registrado
 
Registrado: ene 2005
Posts: 9
Poder: 0
Arkaz Va por buen camino
Busqueda con FindDialog hacia arriba

Hola, estoy intentando realizar la busqueda de una palabra en un texto de un memo con FindDialog. He conseguido que me haga la busqueda hacia abajo con este codigo:

procedure TForm1.FindDialog1Find(Sender: TObject);
var
posicion:integer;
palabra:string;
begin
if frdown in FindDialog1.Options then begin
palabra:=Copy(Memo1.Text,
2+Memo1.SelStart,
Length(Memo1.Text)-Memo1.SelStart);

posicion:=Pos(UpperCase(finddialog1.FindText),UpperCase(palabra));

if posicion<>0 then
begin
Memo1.SetFocus;
Memo1.SelStart:=Memo1.SelStart+posicion;
Memo1.SelLength:=Length(finddialog1.FindText);
end
else begin
ShowMessage('No encuentro '+finddialog1.FindText);
memo1.SelStart:=0;
end;
end;
end;
end;

Pero la busqueda hacia arriba no me sale y no se como hacerla. Me podeis ayudar, por favor?.Gracias!
Responder Con Cita
  #2  
Antiguo 08-02-2005
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Poder: 28
Lepe Va por buen camino
Esta función está sacada de las NKLIB, Tiene muchas otras para el tratamiento de strings, memos, nombres de archivos, etc...
Código Delphi [-]
// Habrá que buscar un algoritmo más eficiente para esto, de momento...
function RightPos(const cSubstr, s: String): Integer;
var
  i: Integer;
begin
  for i := Length(s) - Length(cSubStr) + 1 downto 1 do
  begin
    if Copy(s, i, Length(cSubstr)) = cSubStr then
    begin
      Result := i;
      exit
    end (*if*);
  end (*for*);
  Result := 0;
end (*RightPos*);

Saludos
Responder Con Cita
  #3  
Antiguo 20-04-2010
Rowerto Rowerto is offline
Miembro
 
Registrado: abr 2010
Posts: 20
Poder: 0
Rowerto Va por buen camino
Ya se que llego con unos cuantos años de retraso pero creo que he logrado que la busqueda hacia arriba funcione.

Código Delphi [-]
var foundat, anterior : longint;
    startpos, toend : integer;
begin
    startpos:=0;
    foundat:=0;
    if richedit1.Sellength<>0 then
    begin
      toend := richedit1.SelStart + richedit1.SelLength;
    end
    else
    begin
      toend := length(richedit1.text);
    end;

    while startpos < toend do
    begin
      anterior := foundat;
      foundat := richedit1.findtext(finddialog1.findtext, startpos, toend, [stmatchcase]);
      if (anterior <>-1) then
      begin
        richedit1.SetFocus;
        richedit1.SelStart:=foundat;
        richedit1.SelLength:=length(finddialog1.FindText);
        startpos := richedit1.SelStart + richedit1.SelLength;
      end;
    end;

    if anterior = 0 then
    begin
    MessageDlg('No encuentro '+finddialog1.FindText+' Tal vez hayas llegado al principio.', mtInformation, [mbOk], 0, );
    end
    else
    begin
      richedit1.SetFocus;
      richedit1.SelStart:=anterior;
      richedit1.SelLength:=length(finddialog1.FindText);
      richedit1.Perform(EM_SCROLLCARET, 0, 0);
    end;
   end;

El unico problema es que a la hora de buscar como no le ponga la palabra exacta no me lo encuentra (se que es por el stmatchcase de la busqueda). Alguien me puede decir como puedo hacer?
Responder Con Cita
  #4  
Antiguo 20-04-2010
Rowerto Rowerto is offline
Miembro
 
Registrado: abr 2010
Posts: 20
Poder: 0
Rowerto Va por buen camino
Como soy algo lento y no me di cuenta?

foundat := richedit1.findtext(finddialog1.findtext, startpos, toend, [stmatchcase]);

hay que ponerlo

foundat := richedit1.findtext(finddialog1.findtext, startpos, toend, []);

y ya esta, ya funciona sin tener que poner exactamente la palabra.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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 16:58:10.


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