Jump to content
Fivewin Brasil

Pesquisa em campo em texto


Jmsilva

Recommended Posts

Resolvido !!!

Olá, já andei pesquisando sobre assunto, porém não encontrei o que preciso, inicialmente faço uma pesquisa no dbf seleciono previamente alguns registros através da função WildMatch(), Após gostaria que o usuário digitasse uma palavra e fosse posicionado sobre parte do texto encontrado. Usei o código abaixo, encontra mas o refresh() não funciona.

n:=1
@ 4, 3 GET oMemo VAR cText MEMO OF oDlg PIXEL SIZE 330, 124 FONT oFont
oMemo:lReadOnly := .T. //nÆo edita
oMemo:bGotFocus:={|| oMemo:SetPos(n-1,n+10)}
bSeek :={|| n:=AtSkipSTrings(Trim(cKey),;
Upper(cText)),;
IF(n > 0, Eval(oMemo:bGotFocus,n),;
MsgStop("Não localizado")),;
oMemo:Refresh()}
@ 10.4,12 Get oGT VAR cKey PICTURE "@!" ACTION Eval(bSeek) BITMAP "pwd\find.bmp"

Aguardo ajuda !!!

JMSILVA

Edited by Jmsilva
Link to comment
Share on other sites

Não entendi, este texto está no .DBF? se sim, use o ORDWILDSEEK().

Sim faço a seleção dos registros, trata-se de campo memo, após a pré seleção exibo em um browse, o usuario seleciona o registro e visualiza o texto na tela, porém o texto é longo e perde tempo até encontrar a parte do texto desejado, então criei um campo para digitar uma palavra e faço a pesquisa com a func At(), preciso fazer a rolagem....entendeu agora?

Link to comment
Share on other sites

E se voce guardasse o campo em um texto, salva e usa um editor? Somente uma idéia.


Tipo assim:



// The example demonstrates MemoLine() usage for extracting all lines
// of a text file. The difference of using line numbers versus using
// line offsets is outlined.

PROCEDURE Main( cFileName )

LOCAL nLineLen := 60
LOCAL nTabSize := 8
LOCAL lWrap := .T.
LOCAL i, imax, cText, cLine, nOffSet, nTextLen
LOCAL t1, t2, t3

IF Empty( cFileName ) .OR. .NOT. File( cFileName )
? "No file specified"
QUIT
ENDIF

cText := MemoRead( cFileName )

t1 := Seconds()

imax := MLCount( cText, nLineLen, nTabSize, lWrap )

FOR i:=1 TO imax

cLine := MemoLine( cText, nLineLen, i, nTabSize, lWrap )

NEXT

t2 := Seconds()

// This example shows the use of the <nOffSet> parameter.
// Note that the line number does not change, but the starting
// position in the text to begin extracting a line
nTextLen := Len( cText )
nOffSet := 1

i := 0

DO WHILE nOffSet <= nTextLen

cLine := MemoLine( cText, nLineLen, 1, nTabSize, lWrap,, @nOffSet )

i++

ENDDO

t3 := Seconds()

? "Using line number:", t2-t1, "secs (" + Ltrim(Str(imax)) + " lines)"
? "Using line offset:", t3-t2, "secs (" + Ltrim(Str(i)) + " lines)"

RETURN

Link to comment
Share on other sites

Motta, gostei do autoget, mas não é o que preciso. O que preciso é igual a uma pesquisa editor texto comum, só que usando

GET [ <oGet> VAR <uVar> OF oWnd [ MULTILINE | MEMO | TEXT ]. Também a dica oTexto:Find( "texto a procurar" ) não virou.

valeu !!!

Link to comment
Share on other sites

Aqui funciona legal, mas uso o format get:

@ 09.55,0.5 Format Get oTexto Var Vtexto Memo of oDlg Size 290,100 Font oFont1


@ 12.9,14 Button " &Posiciona " OF oDlg Size 60,12 Action(Efind(oTexto, Vtexto), oTexto:SetFocus())

Function Efind(oTexto, Vtexto)
oTexto:Find( "|" )
oTexto:GoPrevWord()
oTexto:GoNextWord()

Return NIL

Outra alternativa seria usar um for/next com mlcount e memoline e posicionar.

Link to comment
Share on other sites

Valeu, o que precisava era exatamente o "post" abaixo, tirei parte do meu sistema e fiz a rotina completa para quem quiser...ficou dez.


/* 
 * Project: xFF
 * File: xFF.prg
 * Description: 
 * Author: JMSilva
 * Date: 06-25-2014
 */

#INCLUDE "FIVEWIN.CH"

**==========================================
FUNCTION MAIN()
**==========================================
LOCAL oFnt, oDlg, oMemo, oBtnSair, oIco, oBrush
LOCAL oKey,cKey := Space(20),oBtnFind,cText

DEFINE FONT oFnt NAME "TAHOMA" SIZE 00, -12
DEFINE BRUSH oBrush STYLE "BORLAND"  

DEFINE DIALOG oDlg;
       TITLE "Pesquisa com GET TEXT"; //ICON oIco 
       SIZE 680, 480 BRUSH oBrush FONT oFnt;
       STYLE nOR(WS_SYSMENU,WS_MINIMIZEBOX)
oDlg:lHelpIcon := .F. //desabilita botao help

cText := MemoRead("file.txt") //pode ser campo memo

@ 4, 3 GET oMemo VAR cText MEMO OF oDlg PIXEL SIZE 330, 192 FONT oFnt
oMemo:bGotFocus:={|| oMemo:SetSel(0,0) }
oMemo:lReadOnly := .T.  //nÆo edita


@ 14,1 SAY "PESQUISA:" COLOR CLR_HBLUE TRANSPARENT
@ 16,5 Get oKey VAR cKey PICTURE "@!";
         ACTION (Find(oMemo,Trim(cKey),.T.),oBtnFind:Enable())
oKey:bKeyChar := {|| oBtnFind:Disable()}

@ 204, 120 BTNBMP oBtnFind PROMPT "&Próximo" SIZE 40, 18 CENTER 2007;
           ACTION Find(oMemo,Trim(cKey),.F.);
           WHEN Find()
oBtnFind:Disable()

@ 204, 290 BTNBMP oBtnSair PROMPT "&Sair" SIZE 40, 18 CENTER 2007 ;
           ACTION oDlg:End()


ACTIVATE DIALOG oDlg CENTER

oFnt:End()

RETURN NIL



**=======================================================
FUNCTION Find(oMemo,cFind,lNew)
**=======================================================
LOCAL nIndex := 0
Static nStart := 0

IF PCount() == 0 ; RETURN(nStart > 0) ; ENDIF //when
IF lNew ; nStart := 1; ENDIF               //start

nIndex := At(Trim(cFind),Upper(oMemo:cText),nStart,Len(oMemo:cText))
   
IF nIndex > 0
   oMemo:Setfocus()     //seta o focu
   oMemo:SetPos(nIndex-1,nIndex) //posiciona
   oMemo:SetSel(nIndex-1,nIndex+Len(Trim(cFind))-1)
   RESetSelection(oMemo:hWnd, nIndex+Len(Trim(cFind)), nIndex)  //faz a rolagem do texto
   oMemo:Change()
   nSTART := nIndex + Len(Trim(cFind))//para continuar a pesquisa
ELSEIF lNew
   MsgStop( "A palavra: " + cFind +" não foi localizada","Find" )
   oMemo:SetSel(0,0)
   nStart := 1
ELSE
   MsgStop( "Nenhuma outra ocorrência foi encontrada","Find" )
   nIndex := nStart - Len(Trim(cFind))
   oMemo:SetPos(nIndex-1,nIndex) //posiciona
ENDIF
RETURN .T.

Link to comment
Share on other sites

  • 9 years later...

Dei uma melhoradinha...

// C:\FWH\SAMPLES\VICTOR2.PRG
/*
 * Project: xFF
 * File: xFF.prg - Original. Modificado por: kapiabafwh@gmail.com
 * Description:
 * Author: JMSilva
 * Date: 06-25-2014
*/

#Include "Fivewin.ch"

FUNCTION Main()

   LOCAL oFont, oFnt, oDlg, oMemo, oBtnSair, oIco, aGrad, oKey, oBtnFind, ;
         cText, cKey := Space( 20 )

   SetBalloon( .T. ) 
   SkinButtons()

   // Color en el MEMO.
   TGet():bColorBlock := { |oGet| IF( oGet:lFocused, { CLR_BLACK, CLR_HCYAN },     ;
                                  IF( .NOT. oGet:lActive, { CLR_RED, CLR_YELLOW }, ;
                                                          { CLR_BLACK, CLR_WHITE } ) ) }

   cText := MemoRead( "TEXTO.txt" ) // pode ser campo memo

   aGrad := { { 0.30, nRGB( 221, 245, 255 ), nRGB( 192, 221, 255 ) }, ;
              { 0.50, nRGB( 192, 221, 255 ), nRGB( 221, 245, 255 ) } }

   DEFINE FONT oFont NAME "TAHOMA" SIZE 00, - 12 BOLD
   DEFINE FONT oFnt  NAME 'TAHOMA' SIZE 00, - 12 BOLD
   DEFINE ICON oIco FILENAME "..\icons\customer.ico"

   DEFINE DIALOG oDlg TITLE "Pesquisa com GET TEXT" SIZE 680, 480 ICON oIco ;
      GRADIENT aGrad FONT oFont STYLE nOR( WS_SYSMENU, WS_MINIMIZEBOX )

   IF Set( _SET_INSERT, ! Set( _SET_INSERT ) )
      Set( _SET_INSERT, ! Set( _SET_INSERT ) )
   ENDIF

   @ 4, 3 GET oMemo VAR cText MEMO PIXEL SIZE 330, 192 OF oDlg FONT oFont ;
      UPDATE

   oMemo:bGotFocus := {|| oMemo:SetSel( 0, 0 ) }
   oMemo:lReadOnly := .T.  // nÆo edita

   @ 13.10, 07 SAY "<Click> na Lupa Para Procurar: " OF oDlg UPDATE ;
      COLORS METRO_GREEN, CLR_WHITE TRANSPARENT FONT oFnt

   @ 13.85, 1 SAY "PESQUISA: " OF oDlg UPDATE COLORS CLR_HBLUE, CLR_WHITE ;
      TRANSPARENT FONT oFont

   @ 16, 5 GET oKey VAR cKey PICTURE "@!" SIZE 150, 12 OF oDlg ;
      BITMAP "..\bitmaps\Find2.bmp"                            ;
      ACTION ( Find( oMemo, Trim( cKey ), .T. ), oBtnFind:Enable() )

   oKey:cToolTip := "Digite o Texto a Procurar"

   oKey:bKeyChar := {|| oBtnFind:Disable() }

   oKey:lBtnTransparent := .T.
   oKey:lAdjustBtn      := .T.

   @ 203, 195 BTNBMP oBtnFind PROMPT "&Próximo" SIZE 50, 18 OF oDlg ;
      LEFT 2007 FLAT FILENAME "../bitmaps/Next.bmp"                 ;
      ACTION Find( oMemo, Trim( cKey ), .F. ) WHEN( Find() )

   oBtnFind:cToolTip := " Próximo Texto a Procurar"

   oBtnFind:Disable()

   @ 203, 290 BTNBMP oBtnSair PROMPT " &Salir" SIZE 40, 18 OF oDlg  ;
      2007 FLAT LEFT FILENAME "../bitmaps/Exit.bmp" ACTION( oDlg:End() )

   oBtnSair:cToolTip := " Salida - Exit - Cancelar"

   oBtnSair:lCancel := .T.

   ACTIVATE DIALOG oDlg CENTERED ON INIT( XFOCUS( oKey ) )

   IF Set( _SET_INSERT, ! Set( _SET_INSERT ) )
      Set( _SET_INSERT, ! Set( _SET_INSERT ) )
   ENDIF

   oFont:End()
   oFnt:End()

RETURN NIL

FUNCTION Find( oMemo, cFind, lNew )

   LOCAL nIndex := 0

   STATIC nStart := 0

   IF PCount() == 0 ; RETURN( nStart > 0 ) ; ENDIF // when

   IF lNew ; nStart := 1; ENDIF               // start

   nIndex := At( Trim( cFind ), Upper( oMemo:cText ), nStart, Len( oMemo:cText ) )

   IF nIndex > 0

      oMemo:Setfocus()     // seta o focu
      oMemo:SetPos( nIndex - 1, nIndex ) // posiciona
      oMemo:SetSel( nIndex - 1, nIndex + Len( Trim( cFind ) ) - 1 )

      RESetSelection( oMemo:hWnd, nIndex + Len( Trim( cFind ) ), nIndex )  // faz a rolagem do texto

      oMemo:Change()

      nSTART := nIndex + Len( Trim( cFind ) )// para continuar a pesquisa

   ELSEIF lNew

      MsgStop( "A palavra: " + cFind + " não foi localizada", "Find" )

      oMemo:SetSel( 0, 0 )

      nStart := 1

   ELSE

      MsgStop( "Nenhuma outra ocorrência foi encontrada", "Find" )

      nIndex := nStart - Len( Trim( cFind ) )

      oMemo:SetPos( nIndex - 1, nIndex ) // posiciona

   ENDIF

RETURN( .T. )

FUNCTION xFocus( oObj )

   xSetFocus( oObj )
   xSetFocus( oObj )

RETURN( .T. )

FUNCTION xSetFocus( oObj )    

   LOCAL _oWnd := oObj:oWnd, _oTempo := ""

   DEFINE TIMER _oTempo INTERVAL 10 OF _oWnd ;
      ACTION ( oObj:SetFocus(), _oTempo:End() )

   ACTIVATE TIMER _oTempo

RETURN( .T. )

// FIN / END

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...