Scripts para Harbour y FWH !!!

User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Scripts para Harbour y FWH !!!

Post by Antonio Linares »

Este es un poderoso ejemplo de como añadir scripting a vuestras propias aplicaciones:

scripts.prg

Code: Select all

// 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
 
Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Scripts para Harbour y FWH !!!

Post by Antonio Linares »

Version mejorada:

scripts.prg

Code: Select all

// 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/]Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Scripts para Harbour y FWH !!!

Post by lailton.webmaster »

Antonio,

Very good :)
MGA
Posts: 1219
Joined: Mon Feb 25, 2008 2:54 pm
Location: Brasil/PR/Maringá
Contact:

Re: Scripts para Harbour y FWH !!!

Post by MGA »

Sr. Antonio,

Com xharbour: UNRESOLVED EXTERNAL

hb_compilebuf

hb_hrbrun
ubiratanmga@gmail.com

FWH17.04
FWPPC
Harbour/xHarbour
xMate
Pelles´C
TDolphin
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Scripts para Harbour y FWH !!!

Post by lailton.webmaster »

Isto é para Harbour somente ( acredito eu... )
pcordonet
Posts: 110
Joined: Sat Jan 30, 2010 8:35 am
Location: Girona

Re: Scripts para Harbour y FWH !!!

Post by pcordonet »

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

que hace lo mismo.

Libreria xBScript.lib

Pere
User avatar
Sebastián Almirón
Posts: 125
Joined: Mon Dec 12, 2005 9:56 am
Location: Moralzarzal - Spain

Re: Scripts para Harbour y FWH !!!

Post by Sebastián Almirón »

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Scripts para Harbour y FWH !!!

Post by Antonio Linares »

Una version mejorada:

Code: Select all

// 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
Enrrique Vertiz
Posts: 440
Joined: Fri Oct 07, 2005 2:17 pm
Location: Lima - Peru
Contact:

Re: Scripts para Harbour y FWH !!!

Post by Enrrique Vertiz »

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, Fwh 20.04, MySQL 5.7 - 8.0, SQLLIB 1.9m, SQLRDD
pcordonet
Posts: 110
Joined: Sat Jan 30, 2010 8:35 am
Location: Girona

Re: Scripts para Harbour y FWH !!!

Post by pcordonet »

Hola Enrique,

Descargate el contenido de este enlaze:

http://xharbour.cvs.sourceforge.net/vie ... /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
User avatar
Carles
Posts: 937
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona
Contact:

Re: Scripts para Harbour y FWH !!!

Post by Carles »

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..."

https://modharbour.app
https://modharbour.app/compass
https://forum.modharbour.app
Simon
Posts: 105
Joined: Thu Oct 20, 2005 12:29 pm
Location: Maracaibo, Venezuela.

Re: Scripts para Harbour y FWH !!!

Post by Simon »

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: Select all

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.
 
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Scripts para Harbour y FWH !!!

Post by Antonio Linares »

Simón,

Que código es el que intentas ejecutar ?

Prueba con:

Code: Select all

function Test()

   MsgInfo( "Hello world!" )

return nil
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
Simon
Posts: 105
Joined: Thu Oct 20, 2005 12:29 pm
Location: Maracaibo, Venezuela.

Re: Scripts para Harbour y FWH !!!

Post by Simon »

Es el mismo, solo cambie "hello world" por "hola mundo".
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Scripts para Harbour y FWH !!!

Post by anserkk »

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: Select all

DEFINE MSGBAR oMsgBar OF oWnd 2007 PROMPT "Scripting support for your applications"
should be changed to

Code: Select all

DEFINE MSGBAR oMsgBar OF oWnd PROMPT "Scripting support for your applications"
Regards
Anser
Post Reply