Scripts for Harbour and FWH !!!

Scripts for Harbour and FWH !!!

Postby Antonio Linares » Tue May 17, 2011 8:25 am

This is a powerful example that shows you how to add scripting support into your own applications:

scripts.prg
Code: Select all  Expand view
// 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: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Scripts for Harbour and FWH !!!

Postby Antonio Linares » Tue May 17, 2011 10:07 am

Enhanced version:

scripts.prg
Code: Select all  Expand view
// 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
 


Image

Uploaded with ImageShack.us
regards, saludos

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

Re: Scripts for Harbour and FWH !!!

Postby Antonio Linares » Tue May 17, 2011 10:49 pm

An enhanced version:
Code: Select all  Expand view
// 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Scripts for Harbour and FWH !!!

Postby vilian » Wed May 18, 2011 12:17 pm

Antonio,

This works with resources and user functions ?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 975
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: Scripts for Harbour and FWH !!!

Postby Antonio Linares » Thu May 19, 2011 3:32 am

Yes :-)
regards, saludos

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

Re: Scripts for Harbour and FWH !!!

Postby Roberto Parisi » Thu May 19, 2011 6:37 am

It will be great for xHarbour too. But xHarbour don't have CompileFromBuf function :(

Regards,
Roberto Parisi
Roberto Parisi
 
Posts: 116
Joined: Thu Oct 13, 2005 5:14 pm
Location: Italy

Re: Scripts for Harbour and FWH !!!

Postby Otto » Thu May 19, 2011 2:32 pm

Hello Antonio,

Where is the rc/res file suspected to be?
Thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6330
Joined: Fri Oct 07, 2005 7:07 pm

Re: Scripts for Harbour and FWH !!!

Postby Antonio Linares » Thu May 19, 2011 5:48 pm

Otto,

You can directly use resources from a DLL using "SET RESOURCES TO ...", and also use the resources that are included in your original EXE (RC, RES files) :-)
regards, saludos

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

Re: Scripts for Harbour and FWH !!!

Postby Rimantas » Fri May 20, 2011 10:13 am

Antonio Linares wrote:This is a powerful example that shows you how to add scripting support into your own applications:


Excuse Antonio , but as I can see , you copied my idea ... :-)
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: Scripts for Harbour and FWH !!!

Postby Antonio Linares » Fri May 20, 2011 1:18 pm

Rimantas,

It is just a Harbour built-in feature, and it is just to explain everybody how to use it :-)

And as far as I remember I helped you to get it working ;-)
regards, saludos

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

Re: Scripts for Harbour and FWH !!!

Postby Rimantas » Fri May 20, 2011 6:46 pm

Antonio Linares wrote:It is just a Harbour built-in feature, and it is just to explain everybody how to use it :-)
And as far as I remember I helped you to get it working ;-)


:) ... you are rigth , you helped me . Another question - can scripts be debugged ? I have something like tree of scripts , I can run , edit , save , compile them , but at develope stage it can be comfortable to use debugger with breakpoints in scripts .
How to do something like that ?
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 93 guests