Buscar palabra en texto con Xbrowse

Buscar palabra en texto con Xbrowse

Postby cuatecatl82 » Fri Jul 03, 2015 3:06 am

Saludos a todos:

Estoy trabando con visualizar archivos de texto plano, ya tengo resuelto como poder verlos con la clase Xbrowse con el siguiente código.

Code: Select all  Expand view
TextFile()

   local oDlg, oSay, oIco, oGet, oBtn, oBrw, oCol
   local cText:= space(20)
   local lValid:= .F.
   local oTxt  := TTxtFile():New( "Z:\PRUEBAS\MiEditor\Texto.txt", 0 )
   local aGrad := {  {  1/20, RGB( 235, 244, 253 ), RGB( 235, 244, 253 ) }, ;
                     {  1/20, RGB( 125, 162, 206 ), RGB( 125, 162, 206 ) }, ;
                     { 16/20, RGB( 220, 235, 252 ), RGB( 193, 219, 252 ) }, ;
                     {  1/20, RGB( 125, 162, 206 ), RGB( 125, 162, 206 ) }, ;
                     {  1/20, RGB( 235, 244, 253 ), RGB( 235, 244, 253 ) }  }

     DEFINE ICON    oIco RESOURCE "01"
     DEFINE DIALOG  oDlg RESOURCE "HEADERS" TITLE "Revisando Archivos de Texto.." ICON oIco
   REDEFINE SAY     oSay                 ID 100 OF oDlg
   REDEFINE GET     oGet Var cText       ID 200 OF oDlg
   REDEFINE XBROWSE oBrw COLUMNS "cLine" ID 300 OF oDlg OBJECT oTxt FOOTERS
   REDEFINE BUTTON  oBtn                 ID 400 OF oDlg ACTION (lValid:= .T., oDlg:End())

   WITH OBJECT ( oCol := oBrw:aCols[ 1 ] )
      :bFooter   := { || "Linea: " + Ltrim( Str( oTxt:RecNo() ) ) + " / " + LTrim( Str( oTxt:RecCount() ) ) }
      :cHeader   := "Z:\PRUEBAS\MiEditor\Texto.txt"      
   END

   WITH OBJECT oBrw
      :bChange       := { || oCol:RefreshFooter() }
      :bClrSelFocus  := { || { CLR_BLACK, aGrad } }
      :nMarqueeStyle := 4
      :nStretchCol   := 1
      :nRowHeight    := 20
   END

   oDlg:lHelpIcon:= .F.
   
   ACTIVATE DIALOG oDlg centered ON INIT oBrw:SetFocus() VALID lValid

return nil


Quedando de esta manera:
Image

Pero necesito tener un get para buscar palabras, como lo puedo hacer, he buscado en el foro pero solo hay ejemplos en bases de datos, ando algo perdido..

Saludos y gracias..
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México

Re: Buscar palabra en texto con Xbrowse

Postby Francisco Horta » Fri Jul 03, 2015 10:05 pm

Cuate,

a mi esto me va bien con sql, por ahi alguien en el foro me compartio en su momento codigo, no recuerdo (sorry), pero lo devuelo para ayuda:

Code: Select all  Expand view

LOCAL cBusca := "", oStatusBar, cOrden := "nombre"

DEFINE WINDOW :: oChild  ......

DEFINE STATUSBAR oStatusBar OF ::oChild PROMPT cBusca

REDEFINE XBROWSE oBrw ..........

  oBrw:bKeyDown  := { | nKey| IIF( nKey == VK_DELETE, ( this:cAccion := "E", this:BorrarCatalogo()    ),;
                                                IF( nKey == VK_INSERT, ( this:cAccion := "A", this:AgregarCatalogo()   ),;
                                                IF( nKey == VK_RETURN, ( this:cAccion := "M", this:ModificarCatalogo() ),;
                                                IF( nKey <> 13, SeekText(nKey,@::oQry,ALLTRIM(::cTabla),cOrden,::oBrw,@cBusca,oStatusBar,, ::cWhere), )))) }

*---------------------------------------
* FUNCION: SeekText
* Descripcion: Busqueda Incremental
* Fecha: 19/12/2011
*---------------------------------------
FUNCTION SeekText(nKey,oQry2,oTabla,oOrden,oLbx,cBusca,oMsgBar,cSelect,cWhere)
Local cQuery,campo
DEFAULT cSelect := "*",;
        cWhere  := ""

IF nKey=8
   cbusca:= SubStr(cbusca,1,Len(cbusca)-1)
   IF Empty(cWhere)
       cQuery := "SELECT " + cSelect + " FROM " + oTabla + " WHERE " + oOrden + " LIKE '%"+UPPER(cBusca) + "%' ORDER BY " + oOrden
   ELSE
       cQuery := "SELECT " + cSelect + " FROM " + oTabla + " " + cWhere + " AND " + oOrden + " LIKE '%" + UPPER(cBusca) + "%' ORDER BY " + oOrden
   ENDIF
   oQry2:cQuery := cQuery
   oQry2:Refresh()
   oQry2:GoTop()
ELSE
   If nKey=190
      cbusca :=cbusca + "."
   Else
      cbusca :=cbusca + Upper(chr(nkey))
   Endif
   IF Empty(cWhere)
       cQuery := "SELECT " + cSelect + " FROM " + oTabla + " WHERE " + oOrden + " LIKE '%" + UPPER(cBusca) + "%' ORDER BY " + oOrden
   ELSE
       cQuery := "SELECT " + cSelect + " FROM " + oTabla + " " + cWhere + " AND " + oOrden + " LIKE '%" + UPPER(cBusca) + "%' ORDER BY " + oOrden
   ENDIF
   oQry2:cQuery := cQuery
   oQry2:Refresh()
   oQry2:GoTop()
ENDIF
oMsgBar:SetMsg( PadR( cBusca ,200) )
oLbx:Refresh(.T.)
oLbx:SetFocus()

RETURN NIL
 


Saludos
____________________
Paco
Francisco Horta
 
Posts: 845
Joined: Sun Oct 09, 2005 5:36 pm
Location: la laguna, mexico.

Re: Buscar palabra en texto con Xbrowse

Postby cuatecatl82 » Sat Jul 04, 2015 5:19 pm

Hola Pakito:

Gracias por leer mi mensaje, desafortunadamente el código que me ofreces como ejemplo es para buscar texto en una base de datos sql, pero lo que necesito es buscar palabras en un archivo plano de block de notas (.txt), le he buscado y probado pero no me da resultados..

Ojala algun maestro del xbrowse me pueda orientar.. Saludos.
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México

Re: Buscar palabra en texto con Xbrowse

Postby nageswaragunupudi » Mon Jul 06, 2015 8:53 am

TTxtEDit() class is the most suitable class to view and edit any text file. I suggest you try that class for text files instead of xbrowse. The TTxtEDit class has built-in methods for search ,search and replace and many more suitable for text.

After trying TTxtEdit, still if you want to use XBrowse, please let us know and we shall guide you further.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Buscar palabra en texto con Xbrowse

Postby bpd2000 » Tue Jul 07, 2015 4:47 am

There is error while I compile
C:\fwh\samples\testtxte.Prg
Attached screen file

http://www.filedropper.com/testtxteerr
Regards, Greetings

Try FWH. You will enjoy it's simplicity and power.!
User avatar
bpd2000
 
Posts: 153
Joined: Tue Aug 05, 2014 9:48 am
Location: India

Re: Buscar palabra en texto con Xbrowse

Postby cuatecatl82 » Tue Jul 07, 2015 6:01 pm

Saludos Mr. Rao:

TTxtEDit() era una de mis opciones, pero esta bastante incompleta en cuanto a funciones literalmente como decimos en mi pais "esta bastante verde", no soporta el uso del Scroll Vertical del Mouse, la Función ::Search( cText, nFromLine ) No funciona, y menos remarca la palabra que se esta buscando, lo más proximo a lo que necesito esta en la clase TTxtFile(), su apariencia no es muy bonita, y no hay ejemplos, para poder usarlo desde recursos me llevo un rato pero funciona, ademas de que presenta errores al cerrar el dialogo que lo contiene, y al volver a abrirlo:

TTxtEDit() it was one of my choices, but this very incomplete in terms of functions literally as we say in my country " this pretty green " does not support the use of vertical Scroll Mouse, Function :: Search ( cText , nFromLine ) does not work , and but highlights the word being searched , as close to what I need is in the TTxtFile class () , its appearance is not very nice , and there are no examples , so you can use from resources I take a while but it works, besides having errors when closing the dialog containing it, and reopen it :

Code: Select all  Expand view
#INCLUDE "FiveWin.CH"

Function TextFile()

   local oDlg, oSay, oIco, oGet, oBtn, oTxt, xText
   local cText:= space(20)
   local aGrad := {  {  1/20, RGB( 235, 244, 253 ), RGB( 235, 244, 253 ) }, ;
                     {  1/20, RGB( 125, 162, 206 ), RGB( 125, 162, 206 ) }, ;
                     { 16/20, RGB( 220, 235, 252 ), RGB( 193, 219, 252 ) }, ;
                     {  1/20, RGB( 125, 162, 206 ), RGB( 125, 162, 206 ) }, ;
                     {  1/20, RGB( 235, 244, 253 ), RGB( 235, 244, 253 ) }  }

     DEFINE ICON    oIco RESOURCE "01"
     DEFINE DIALOG  oDlg RESOURCE "HEADERS" TITLE "Revisando Archivos de Texto.." ICON oIco
   REDEFINE SAY     oSay                 ID 100 OF oDlg
   REDEFINE GET     oGet Var cText       ID 200 OF oDlg valid (xText:= alltrim(cText), oTxt:Search(xText,1),.T.)
   REDEFINE BUTTON  oBtn                 ID 400 OF oDlg ACTION (oDlg:End())

   oTxt:= TTxtEdit():Redefine(300, oDlg)
 
  oTxt:lReadOnly = .T.  
  oTxt:Load("Z:\PRUEBAS\MiEditor\Texto.txt")
  oTxt:SetLineNumber(.F.)
  oTxt:nClrLineNumber := RGB( 220,220,220 )

  oDlg:lHelpIcon:= .F.
   
   ACTIVATE DIALOG oDlg Centered

return nil


Image
FiveWin Version: FWH 11.11
Windows version: 5.1, Build 2600 Service Pack 3

Time from start: 0 hours 0 mins 8 secs
Error occurred at: 07/07/15, 12:39:22
Error description: Error BASE/1004 No exported method: HBRUSH
Args:
[ 1] = U

Stack Calls
===========
Called from: => HBRUSH( 0 )
Called from: .\source\classes\TTXTEDIT.PRG => TTXTEDIT:PAINT( 1092 )
Called from: .\source\classes\TTXTEDIT.PRG => (b)TTXTEDIT( 94 )
Called from: .\source\classes\TTXTEDIT.PRG => TTXTEDIT:DISPLAY( 0 )
Called from: .\source\classes\CONTROL.PRG => TTXTEDIT:HANDLEEVENT( 1699 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3345 )
Called from: => DIALOGBOX( 0 )
Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 286 )
Called from: Headers.prg => TEXTFILE( 28 )
Called from: MiEditor.prg => (b)BUILDRIBBONBAR( 60 )
Called from: .\source\classes\TRBTN.PRG => TRBTN:CLICK( 714 )
Called from: .\source\classes\TRBTN.PRG => TRBTN:LBUTTONUP( 923 )
Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1723 )
Called from: .\source\classes\TRBTN.PRG => TRBTN:HANDLEEVENT( 1596 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3345 )
Called from: => WINRUN( 0 )
Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE( 1050 )
Called from: MiEditor.prg => PRINCIPAL( 28 )
Called from: MiEditor.prg => MAIN( 14 )

System
======
CPU type: Intel(R) Pentium(R) D CPU 3.20GHz 3200 Mhz
Hardware memory: 1022 megs

Free System resources: 90 %
GDI resources: 90 %
User resources: 90 %

Windows total applications running: 6
1 , C:\WINDOWS\WinSxS\X86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
2 , C:\WINDOWS\system32\SHLWAPI.dll
3 FiveTech Software tech support forums • Ver Tema - Buscar palabra en texto con Xbrowse,
4 MediaCenter, Z:\PRUEBAS\MiEditor\freeimage.dll
5 MiEditor: Consola de depuración Z:\PRUEBAS\MiEditor\MiEditor.Exe (0 errores, 0 a tener en cuenta "Warnings"), Z:\PRUEBAS\MiEditor\MiEditor.Exe
6 SysFader, C:\WINDOWS\system32\SHELL32.DLL

Variables in use
================
Procedure Type Value
==========================
HBRUSH
Param 1: O Class: ERROR
TTXTEDIT:PAINT
Local 1: U
Local 2: U
(b)TTXTEDIT
Local 1: U
Local 2: U
Local 3: A Len: 5
Local 4: U
Local 5: S
Local 6: U
Local 7: N -1895752748
Local 8: A Len: 4
TTXTEDIT:DISPLAY
Param 1: O Class: TTXTEDIT
TTXTEDIT:HANDLEEVENT
_FWH
Param 1: N 15
Param 2: N 0
Param 3: N 0
Local 1: U
DIALOGBOX
Param 1: N 0
Param 2: N 15
Param 3: N 0
Param 4: N 0
Param 5: N 28
Local 1: O Class: TTXTEDIT
TDIALOG:ACTIVATE
Param 1: N 4194304
Param 2: C "HEADERS"
Param 3: N 7537254
Param 4: O Class: TDIALOG
TEXTFILE
Param 1: U
Param 2: U
Param 3: U
Param 4: L .T.
Param 5: U
Param 6: L .T.
Param 7: U
Param 8: U
Param 9: U
Param 10: L .F.
Param 11: L .F.
Local 1: N 7537254
Local 2: S
Local 3: O Class: TDIALOG
(b)BUILDRIBBONBAR
Local 1: O Class: TDIALOG
Local 2: O Class: TSAY
Local 3: O Class: TICON
Local 4: O Class: TGET
Local 5: O Class: TBUTTON
Local 6: O Class: TTXTEDIT
Local 7: U
Local 8: C " "
Local 9: A Len: 5
TRBTN:CLICK
Param 1: O Class: TRBTN
TRBTN:LBUTTONUP
TCONTROL:HANDLEEVENT
Param 1: N 60
Param 2: N 39
Param 3: N 0
Local 1: L .T.
Local 2: L .T.
Local 3: S
TRBTN:HANDLEEVENT
Param 1: N 514
Param 2: N 0
Param 3: N 3932199
Local 1: U
_FWH
Param 1: N 514
Param 2: N 0
Param 3: N 3932199
WINRUN
Param 1: N 3932199
Param 2: N 514
Param 3: N 0
Param 4: N 3932199
Param 5: N 7
Local 1: O Class: TRBTN
TWINDOW:ACTIVATE
Param 1: N 7537254
PRINCIPAL
Param 1: C "MAXIMIZED"
Param 2: U
Param 3: U
Param 4: U
Param 5: U
Param 6: U
Param 7: U
Param 8: B {|| ... }
Param 9: U
Param 10: U
Param 11: U
Param 12: U
Param 13: U
Param 14: U
Param 15: U
Param 16: U
Param 17: B {|| ... }
Param 18: U
Param 19: U
Param 20: L .F.
Local 1: O Class: TWINDOW
Local 2: U
Local 3: U
MAIN
Local 1: O Class: TICON

Linked RDDs
===========
DBF
DBFFPT
DBFBLOB
DBFNTX

DataBases in use
================

Classes in use:
===============
1 ERROR
2 HBCLASS
3 HBOBJECT
4 MISDATOS
5 TWINDOW
6 TCONTROL
7 TICON
8 TBRUSH
9 TFONT
10 TMSGBAR
11 TRECT
12 TBITMAP
13 TIMAGE
14 TRIBBONBAR
15 TRPANEL
16 TRBGROUP
17 TRBTN
18 TDIALOG
19 TSAY
20 TGET
21 GET
22 TCLIPGET
23 TBUTTON
24 TTXTEDIT
25 TSCROLLBAR
26 TREG32

Memory Analysis
===============
223 Static variables

Dynamic memory consume:
Actual Value: 0 bytes
Highest Value: 0 bytes

Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 71 guests