Page 1 of 3
Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 8:33 am
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
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 10:08 am
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/]
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 1:27 pm
by lailton.webmaster
Antonio,
Very good
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 2:57 pm
by MGA
Sr. Antonio,
Com xharbour: UNRESOLVED EXTERNAL
hb_compilebuf
hb_hrbrun
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 3:15 pm
by lailton.webmaster
Isto é para Harbour somente ( acredito eu... )
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 3:29 pm
by pcordonet
Con xHarbour existe una classe TInterpreter(), en utils\xbs_harb.ch
que hace lo mismo.
Libreria xBScript.lib
Pere
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 4:12 pm
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
Saludos
Re: Scripts para Harbour y FWH !!!
Posted: Tue May 17, 2011 10:50 pm
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
Re: Scripts para Harbour y FWH !!!
Posted: Wed May 18, 2011 2:04 am
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.
Re: Scripts para Harbour y FWH !!!
Posted: Wed May 18, 2011 6:37 am
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
Re: Scripts para Harbour y FWH !!!
Posted: Wed May 18, 2011 7:53 am
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.
Re: Scripts para Harbour y FWH !!!
Posted: Wed May 18, 2011 11:02 pm
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.
Re: Scripts para Harbour y FWH !!!
Posted: Thu May 19, 2011 3:31 am
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
Re: Scripts para Harbour y FWH !!!
Posted: Thu May 19, 2011 3:43 am
by Simon
Es el mismo, solo cambie "hello world" por "hola mundo".
Re: Scripts para Harbour y FWH !!!
Posted: Thu May 19, 2011 4:19 am
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