FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Scripts para Harbour y FWH !!!
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 08:33 AM
Este es un poderoso ejemplo de como a帽adir scripting a vuestras propias aplicaciones:

scripts.prg
Code (fw): Select all Collapse
// Scripting for Harbour and FiveWin only (not supported on xHarbour)

#include "FiveWin.ch"
#include "Splitter.ch"
#include "xbrowse.ch"

static oWnd

function Main()

聽 聽local oBrw, oFont, oMemo, oSplit
聽 聽
聽 聽if ! File( "scripts.dbf" )
聽 聽 聽 DbCreate( "scripts.dbf", { { "NAME", "C", 20, 0 }, { "DESCRIPT", "C", 100, 0 }, { "CODE", "M", 80, 0 } } )
聽 聽endif 聽 聽 聽
聽 聽
聽 聽USE scripts
聽 聽
聽 聽if RecCount() == 0
聽 聽 聽 APPEND BLANK
聽 聽 聽 Scripts->Name := "Test"
聽 聽 聽 Scripts->Descript := "This is a test script"
聽     Scripts->Code := "function Test()" + CRLF + CRLF + '   MsgInfo( "Hello world!" )' + CRLF + CRLF + "return nil"
聽 聽endif 聽 
聽 聽
聽 聽DEFINE WINDOW oWnd TITLE "Scripts" MENU BuildMenu()
聽 聽
聽 聽DEFINE BUTTONBAR oBar OF oWnd SIZE 80, 80 2007
聽 聽
聽 聽DEFINE BUTTON OF oBar PROMPT "New" FILE "..\bitmaps\alphabmp\plus.bmp" TOOLTIP "New"

聽 聽DEFINE BUTTON OF oBar PROMPT "Run" FILE "..\bitmaps\alphabmp\task.bmp" TOOLTIP "Run" ACTION Execute()

聽 聽DEFINE BUTTON OF oBar PROMPT "Exit" 聽FILE "..\bitmaps\32x32\quit.bmp" TOOLTIP "Exit" ;
聽 聽 聽 ACTION If( MsgYesNo( "Do you want to end ?" ), oWnd:End(),)
聽 聽 聽 
聽 聽@ 5.8, 0 XBROWSE oBrw OF oWnd SIZE 450, 500 ;
聽 聽 聽 FIELDS Scripts->Name, Scripts->Descript ;
聽 聽 聽 HEADERS "Name", "Description" CELL LINES
聽 聽
聽 聽oBrw:CreateFromCode() 聽 
聽 聽 聽 
聽 聽DEFINE FONT oFont NAME "Courier New" SIZE 0, -14 聽 
聽 聽 聽 
聽 聽@ 6.3, 57 GET oMemo VAR Scripts->Code MEMO OF oWnd SIZE 500, 500 FONT oFont
聽 聽
聽 聽@ 0, 450 SPLITTER oSplit ;
聽 聽 聽 VERTICAL _3DLOOK ;
聽 聽 聽 PREVIOUS CONTROLS oBrw ;
聽 聽 聽 HINDS CONTROLS oMemo ; 
聽 聽 聽 SIZE 4, 200 PIXEL ;
聽 聽 聽 OF oWnd
聽 聽 聽 
聽 聽oSplit:AdjClient() 聽 聽 聽 聽 
聽 聽
聽 聽DEFINE MSGBAR oMsgBar OF oWnd 2007 PROMPT "Scripting support for your applications"
聽 聽
聽 聽ACTIVATE WINDOW oWnd MAXIMIZED ;
聽 聽 聽 ON RESIZE oSplit:AdjClient() 聽 
聽 聽
return nil

function BuildMenu()

聽 聽local oMenu
聽 聽
聽 聽MENU oMenu
聽 聽 聽 MENUITEM "Scripts management"
聽 聽 聽 MENU
聽 聽 聽 聽 聽MENUITEM "About..." ACTION MsgAbout( "Scripting support for Harbour and FiveWin", "(c) FiveTech Software 2011" )
聽 聽 聽 聽 聽SEPARATOR
聽 聽 聽 聽 聽MENUITEM "Exit" ACTION If( MsgYesNo( "Do you want to end ?" ), oWnd:End(),)
聽 聽 聽 ENDMENU 聽 
聽 聽ENDMENU
聽 聽
return oMenu 聽 聽 聽

function Execute()

聽 聽local oHrb

聽 聽MemoWrit( "_temp.prg", Scripts->Code )
聽 聽FReOpen_Stderr( "comp.log", "w" )
聽 聽oHrb = HB_CompileBuf( HB_ARGV( 0 ), "_temp.prg", "-n", "-Ic:\fwh\include" )
聽 聽// MsgInfo( MemoRead( "comp.log" ) )
聽 聽hb_HrbRun( oHrb )

return nil

#pragma BEGINDUMP

#include <stdio.h>
#include <hbapi.h>

HB_FUNC( FREOPEN_STDERR )
{
聽 聽hb_retnl( ( LONG ) freopen( hb_parc( 1 ), hb_parc( 2 ), stderr ) );
} 聽 聽

#pragma ENDDUMP


regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 10:08 AM
Version mejorada:

scripts.prg
Code (fw): Select all Collapse
// Scripting for Harbour and FiveWin only (not supported on xHarbour)

#include "FiveWin.ch"
#include "Splitter.ch"
#include "xbrowse.ch"

static oWnd, oResult

function Main()

聽 聽local oBrw, oFont, oMemo, oSplit, oSplit2
聽 聽local cCode := '#include "FiveWin.ch"' + CRLF + CRLF + "function Test()" + CRLF + CRLF + ' 聽 MsgInfo( "Hello world!" )' + CRLF + CRLF + "return nil"
聽 聽local cResult
聽 聽
聽 聽if ! File( "scripts.dbf" )
聽 聽 聽 DbCreate( "scripts.dbf", { { "NAME", "C", 20, 0 }, { "DESCRIPT", "C", 100, 0 }, { "CODE", "M", 80, 0 } } )
聽 聽endif 聽 聽 聽
聽 聽
聽 聽USE scripts
聽 聽
聽 聽if RecCount() == 0
聽 聽 聽 APPEND BLANK
聽 聽 聽 Scripts->Name := "Test"
聽 聽 聽 Scripts->Descript := "This is a test script"
聽 聽 聽 Scripts->Code := cCode
聽 聽endif 聽 
聽 聽
聽 聽DEFINE WINDOW oWnd TITLE "Scripts" MENU BuildMenu()
聽 聽
聽 聽DEFINE BUTTONBAR oBar OF oWnd SIZE 80, 80 2007
聽 聽
聽 聽DEFINE BUTTON OF oBar PROMPT "New" FILE "..\bitmaps\alphabmp\plus.bmp" TOOLTIP "New" ACTION ( DbAppend(), Scripts->Name := "new script", oBrw:Refresh(), oMemo:SetText( cCode ) )

聽 聽DEFINE BUTTON OF oBar PROMPT "Run" FILE "..\bitmaps\alphabmp\task.bmp" TOOLTIP "Run" ACTION Execute()

聽 聽DEFINE BUTTON OF oBar PROMPT "Exit" 聽FILE "..\bitmaps\32x32\quit.bmp" TOOLTIP "Exit" ;
聽 聽 聽 ACTION If( MsgYesNo( "Do you want to end ?" ), oWnd:End(),)
聽 聽 聽 
聽 聽@ 5.8, 0 XBROWSE oBrw OF oWnd SIZE 450, 500 ;
聽 聽 聽 FIELDS Scripts->Name, Scripts->Descript ;
聽 聽 聽 HEADERS "Name", "Description" CELL LINES ;
聽 聽 聽 ON CHANGE ( oMemo:SetText( Scripts->Code ), oMemo:Refresh() )
聽 聽
聽 聽oBrw:lFastEdit = .T.
聽 聽oBrw:CreateFromCode() 聽 
聽 聽 聽 
聽 聽DEFINE FONT oFont NAME "Courier New" SIZE 0, -14 聽 
聽 聽 聽 
聽 聽@ 6.3, 57 GET oMemo VAR Scripts->Code MEMO OF oWnd SIZE 500, 569 FONT oFont
聽 聽
聽 聽@ 50.5, 57 GET oResult VAR cResult MEMO OF oWnd SIZE 500, 300 FONT oFont
聽 聽
聽 聽@ 0, 450 SPLITTER oSplit ;
聽 聽 聽 VERTICAL _3DLOOK ;
聽 聽 聽 PREVIOUS CONTROLS oBrw ;
聽 聽 聽 HINDS CONTROLS oMemo, oResult ; 
聽 聽 聽 SIZE 4, 200 PIXEL ;
聽 聽 聽 OF oWnd
聽 聽 聽 
聽 聽@ 650, 460 SPLITTER oSplit2 ;
聽 聽 聽 聽 聽 聽 HORIZONTAL _3DLOOK ;
聽 聽 聽 聽 聽 聽 PREVIOUS CONTROLS oMemo ;
聽 聽 聽 聽 聽 聽 HINDS CONTROLS oResult ;
聽 聽 聽 聽 聽 聽 SIZE 500, 4 聽PIXEL ;
聽 聽 聽 聽 聽 聽 OF oWnd 
聽 聽
聽 聽DEFINE MSGBAR oMsgBar OF oWnd 2007 PROMPT "Scripting support for your applications"
聽 聽
聽 聽ACTIVATE WINDOW oWnd MAXIMIZED ;
聽 聽 聽 ON RESIZE ( oSplit:AdjLeft(), oSplit2:AdjRight() ) 聽 
聽 聽
return nil

function BuildMenu()

聽 聽local oMenu
聽 聽
聽 聽MENU oMenu
聽 聽 聽 MENUITEM "Scripts management"
聽 聽 聽 MENU
聽 聽 聽 聽 聽MENUITEM "About..." ACTION MsgAbout( "Scripting support for Harbour and FiveWin", "(c) FiveTech Software 2011" )
聽 聽 聽 聽 聽SEPARATOR
聽 聽 聽 聽 聽MENUITEM "Exit" ACTION If( MsgYesNo( "Do you want to end ?" ), oWnd:End(),)
聽 聽 聽 ENDMENU 聽 
聽 聽ENDMENU
聽 聽
return oMenu 聽 聽 聽

function Execute()

聽 聽local oHrb, cResult 

聽 聽MemoWrit( "_temp.prg", Scripts->Code )
聽 聽// FReOpen_Stderr( "comp.log", "w" )
聽 聽oHrb = HB_CompileBuf( HB_ARGV( 0 ), "_temp.prg", "-n", "-Ic:\fwh\include", "-Ic:\harbour\include" )
聽 聽oResult:SetText( If( Empty( cResult := MemoRead( "comp.log" ) ), "ok", cResult ) )
聽 聽hb_HrbRun( oHrb )

return nil

#pragma BEGINDUMP

#include <stdio.h>
#include <hbapi.h>

HB_FUNC( FREOPEN_STDERR )
{
聽 聽hb_retnl( ( LONG ) freopen( hb_parc( 1 ), hb_parc( 2 ), stderr ) );
} 聽 聽

#pragma ENDDUMP


[URL=http://imageshack.us/photo/my-images/84/clip1v.jpg/]
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 01:27 PM

Antonio,

Very good :)

Posts: 1286
Joined: Mon Feb 25, 2008 02:54 PM
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 02:57 PM

Sr. Antonio,

Com xharbour: UNRESOLVED EXTERNAL

hb_compilebuf

hb_hrbrun

ubiratanmga@gmail.com

FWH24.04
BCC7.3
HARBOUR3.2
xMate
Pelles麓C
TDolphin
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 03:15 PM

Isto 茅 para Harbour somente ( acredito eu... )

Posts: 111
Joined: Sat Jan 30, 2010 08:35 AM
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 03:29 PM

Con xHarbour existe una classe TInterpreter(), en utils\xbs_harb.ch

que hace lo mismo.

Libreria xBScript.lib

Pere

Posts: 166
Joined: Mon Dec 12, 2005 09:56 AM
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 04:12 PM

Yo llevo a帽os usando la clase TScript que venia con las primeras versiones del FTDN (Creo recordar de OZ) sin problemas en FWH.

La verdad es que si le encuentras utilidad es una pasada. Yo tengo montado un sistema de c谩lculo de c贸digos de piezas en una fabrica y los usuarios se encargan de hacer los scripts (a veces con mi ayuda) que devuelven los c贸digos apropiados de las piezas de cada maquina, tomando datos de libros excel, con f贸rmulas, literales, etc. Est谩n disponibles todas las funciones de Harbourr, las de Fivewin, las propias de mi aplicaci贸n, las de un objeto Excel declarado previamente, etc.

Vamos, nada que envidiar al lenguaje VB de Office :P

Saludos

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 10:50 PM
Una version mejorada:
Code (fw): Select all Collapse
// Scripting for Harbour and FiveWin only (not supported on xHarbour)

#include "FiveWin.ch"
#include "Splitter.ch"
#include "xbrowse.ch"

static oWnd, oResult

function Main()

   local oBrw, oFont, oMemo, oSplit, oSplit2
   local cCode := '#include "FiveWin.ch"' + CRLF + CRLF + "function Test()" + CRLF + CRLF + '   MsgInfo( "Hello world!" )' + CRLF + CRLF + "return nil"
   local cResult
   
   if ! File( "scripts.dbf" )
      DbCreate( "scripts.dbf", { { "NAME", "C", 20, 0 }, { "DESCRIPT", "C", 100, 0 }, { "CODE", "M", 80, 0 } } )
   endif      
   
   USE scripts
   
   if RecCount() == 0
      APPEND BLANK
      Scripts->Name := "Test"
      Scripts->Descript := "This is a test script"
      Scripts->Code := cCode
   endif   
   
   DEFINE WINDOW oWnd TITLE "Scripts" MENU BuildMenu()
   
   DEFINE BUTTONBAR oBar OF oWnd SIZE 80, 80 2007
   
   DEFINE BUTTON OF oBar PROMPT "New" FILE "..\bitmaps\alphabmp\plus.bmp" TOOLTIP "New" ACTION ( DbAppend(), Scripts->Name := "new script", oBrw:Refresh(), oMemo:SetText( cCode ) )

   DEFINE BUTTON OF oBar PROMPT "Run" FILE "..\bitmaps\alphabmp\task.bmp" TOOLTIP "Run" ACTION Execute()

   DEFINE BUTTON OF oBar PROMPT "Exit"  FILE "..\bitmaps\32x32\quit.bmp" TOOLTIP "Exit" ;
      ACTION If( MsgYesNo( "Do you want to end ?" ), oWnd:End(),)
      
   @ 5.8, 0 XBROWSE oBrw OF oWnd SIZE 450, 500 ;
      FIELDS Scripts->Name, Scripts->Descript ;
      HEADERS "Name", "Description" CELL LINES ;
      ON CHANGE ( oMemo:SetText( Scripts->Code ), oMemo:Refresh() )
   
   oBrw:lFastEdit = .T.
   oBrw:CreateFromCode()   
      
   DEFINE FONT oFont NAME "Courier New" SIZE 0, -14   
      
   @ 6.3, 57 GET oMemo VAR Scripts->Code MEMO OF oWnd SIZE 500, 569 FONT oFont
   
   @ 50.5, 57 GET oResult VAR cResult MEMO OF oWnd SIZE 500, 300 FONT oFont
   
   @ 0, 450 SPLITTER oSplit ;
      VERTICAL _3DLOOK ;
      PREVIOUS CONTROLS oBrw ;
      HINDS CONTROLS oMemo, oResult ; 
      SIZE 4, 200 PIXEL ;
      OF oWnd
      
   @ 650, 460 SPLITTER oSplit2 ;
            HORIZONTAL _3DLOOK ;
            PREVIOUS CONTROLS oMemo ;
            HINDS CONTROLS oResult ;
            SIZE 500, 4  PIXEL ;
            OF oWnd 
   
   DEFINE MSGBAR oMsgBar OF oWnd 2007 PROMPT "Scripting support for your applications"
   
   ACTIVATE WINDOW oWnd MAXIMIZED ;
      ON RESIZE ( oSplit:AdjLeft(), oSplit2:AdjRight() )   
   
return nil

function BuildMenu()

   local oMenu
   
   MENU oMenu
      MENUITEM "Scripts management"
      MENU
         MENUITEM "About..." ACTION MsgAbout( "Scripting support for Harbour and FiveWin", "(c) FiveTech Software 2011" )
         SEPARATOR
         MENUITEM "Exit" ACTION If( MsgYesNo( "Do you want to end ?" ), oWnd:End(),)
      ENDMENU   
   ENDMENU
   
return oMenu      

function Execute()

   local oHrb, cResult 

   FReOpen_Stderr( "comp.log", "w" )
   oHrb = HB_CompileFromBuf( Scripts->Code, "-n", "-Ic:\fwh\include", "-Ic:\harbour\include" )
   oResult:SetText( If( Empty( cResult := MemoRead( "comp.log" ) ), "ok", cResult ) )
   
   if ! Empty( oHrb )
      hb_HrbRun( oHrb )
   endif   

return nil

#pragma BEGINDUMP

#include <stdio.h>
#include <hbapi.h>

HB_FUNC( FREOPEN_STDERR )
{
   hb_retnl( ( LONG ) freopen( hb_parc( 1 ), hb_parc( 2 ), stderr ) );
}    

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Scripts para Harbour y FWH !!!
Posted: Wed May 18, 2011 02:04 AM

Pere

Inidcas que con xHarbour, se puede, te refieres a la version comercial xHarbour.com ?
Pues la version libre, no tiene la libreria ni el .ch que mencionas.

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 111
Joined: Sat Jan 30, 2010 08:35 AM
Re: Scripts para Harbour y FWH !!!
Posted: Wed May 18, 2011 06:37 AM
Hola Enrique,

Descargate el contenido de este enlaze:

http://xharbour.cvs.sourceforge.net/viewvc/xharbour/xharbour/utils/xbscript/

Yo utilizo la version comercial y tengo la libreria compilada.

Precisamente hace unos dias que lo utiliz茅 para un programa de conversion de datos, por eso lo cuento.

Pere
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: Scripts para Harbour y FWH !!!
Posted: Wed May 18, 2011 07:53 AM

Sebastian.

Tscript() fue y es una clase que lleva al limite el uso de la macro. Realmente funciona bien y yo la use durante mucho tiempo, pero ahora tienes que diferenciar un tema y es que no es lo mismo ejecutar pcode que evaluar macros. Este punto lo notaras muchisimo en todos aquellos scripts en q hagas uso de iteraciones, en la que el cambio de metodologia de uso de scripts de una manera es radicalmente opuesta en tiempo de ejecucion.

Salutacions, saludos, regards

"...programar es f谩cil, hacer programas es dif铆cil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 105
Joined: Thu Oct 20, 2005 12:29 PM
Re: Scripts para Harbour y FWH !!!
Posted: Wed May 18, 2011 11:02 PM
Antonio, compile la ultima versi贸n y al darle Run no hace nada, reviso en el panel de resultado y dice que no se ha generado porque hay un error.
uso fivewin 10.12 y bcc 5.82.

Anexo el archivo comp.log que general el programa.

Code (fw): Select all Collapse
Harbour 2.1.0beta1 (Rev. 14559)
Copyright (c) 1999-2010, http://www.harbour-project.org/

100

100

100

100

200

300

400

500

600

100

200

100

200

100

200

300

400

500

600

700

800

900

1000

1100

1200

1300

1400

1500

1600

1 error

No code generated.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Scripts para Harbour y FWH !!!
Posted: Thu May 19, 2011 03:31 AM
Sim贸n,

Que c贸digo es el que intentas ejecutar ?

Prueba con:
Code (fw): Select all Collapse
function Test()

   MsgInfo( "Hello world!" )

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 105
Joined: Thu Oct 20, 2005 12:29 PM
Re: Scripts para Harbour y FWH !!!
Posted: Thu May 19, 2011 03:43 AM

Es el mismo, solo cambie "hello world" por "hola mundo".

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Scripts para Harbour y FWH !!!
Posted: Thu May 19, 2011 04:19 AM
Mr.Simon,
Please remove the keyword 2007 from the MsgBar Definition and then try to run the last scripting example code posted by Mr.Antonio
The following line
Code (fw): Select all Collapse
DEFINE MSGBAR oMsgBar OF oWnd 2007 PROMPT "Scripting support for your applications"

should be changed to
Code (fw): Select all Collapse
DEFINE MSGBAR oMsgBar OF oWnd PROMPT "Scripting support for your applications"


Regards
Anser