Page 1 of 3

Scripting ...

PostPosted: Wed Oct 31, 2007 6:08 pm
by Rimantas
This question is adressed to Antonio. I know that xHB have "xHbScript" . It's requirement to have something to FWH , that script will support good FWH things ... :-) . What you can say , Antonio ? ... Or maybe it's any other technique which can support FWH libs ? I'm asking for that , because it's ideas to do own ERP more flexible and , I'm thinking , scripting with FWH can do this job ... :-)

With best regards ! Rimantas

PostPosted: Thu Nov 01, 2007 6:30 am
by Antonio Linares
Rimantas,

You may use xHB's "xHbScript", it works fine with FWH

PostPosted: Thu Nov 01, 2007 9:16 am
by Rimantas
Antonio Linares wrote:Rimantas,

You may use xHB's "xHbScript", it works fine with FWH


I know xhbScript . But I have in mind scripts which can work with FWH syntax . As a sample - open dialog with some controls - gets , buttons :

Code: Select all  Expand view
#include "FiveWin.ch"
function Main()

   local oDlg, lExit := .f., oBtn

   DEFINE DIALOG oDlg FROM 5, 5 TO 15, 40 TITLE "A Dialog Box"

   @ 3,  4 BUTTON "&Ok" OF oDlg SIZE 40, 12

   @ 3, 12 BUTTON oBtn PROMPT "&Cancel" OF oDlg SIZE 40, 12 ;
      ACTION ( MsgInfo( "Cancel" ), lExit := .t., oDlg:End() )

   ACTIVATE DIALOG oDlg VALID lExit

return nil


Will this code work with xHbScript ?

Regards !

PostPosted: Thu Nov 01, 2007 9:41 am
by Antonio Linares
Rimantas,

I have not tested it myself, but it should work ok :-)

PostPosted: Thu Nov 01, 2007 2:13 pm
by James Bott
Rimantas,

I'm just curious, where are you going with this? What is the advantage to using script insead of code?

James

PostPosted: Thu Nov 01, 2007 5:05 pm
by Rimantas
James Bott wrote:I'm just curious, where are you going with this? What is the advantage to using script insead of code?


Hello James ,

At first I want to to specify , that I'm talking about separate prgs as scripts ... It can be prg as script can run , or xbs , ppo files as they are supported from xharbour.com ...

Exist many places where the scripts are better than code . One of the best place to fit scripts are reports ... Today I'm addidng code inside exe for any report . I'm thinking that this can be changed in other way - put prg's or ppo's files in special directory , from main program in report menu ( generated from DBF ,which contain list of reports ) call needful report = script ... With database it's all working OK . But at the beggining of report I'm calling dialog/window in which user direct needfulls parameters for report . Of course , all the code is with FWH ...

I begin from reports , because this place must be very flexible - at the begining of new project users don't know possibilities of programmer and programmer can't to see future - what users will ask ... :) . So , in mine mind , directory with prg's or precompiled ppo's , maybe xbs's , files it's the easiest way to manage such things . Now , I'm adding code , rebuilding exe , and then placing the new exe remotely in users servers . I'm thinkig that remotely to do new prg file or modify old its more easy ...

Antonio , sorry , but xbScript don't support FWH syntax . I renamed dlg.prg to dlg.xbs and tried to open that . It return error dialog with "compilation error" message ... :( Maybe it's working and I don't know how to to run that .

So I'm asking you , that maybe something similar exist in FWH or xHarbour ...

Regards , Rimantas

PostPosted: Thu Nov 01, 2007 9:26 pm
by Antonio Linares
Rimantas,

I just forgot this: Harbour natively supports dynamic scripting! :-) There is no need for you to use a third party scripting tool!

You create a HRB file on runtime and execute it from the application, so there is no limitations at all and you can execute any Harbour code :-)

Let me find some samples for you.

James, runtime scripting is an incredible powerfull feature, that allows to have full data driven support in your applications :-) Its the foundation of ERP applications

PostPosted: Fri Nov 02, 2007 12:09 am
by Antonio Linares
Rimantas,

Do you use Harbour or xHarbour ?

PostPosted: Fri Nov 02, 2007 2:57 am
by nageswaragunupudi
I have been watching this topic with interest. I am using xharbour (bcc) now. But like to know the possibilities of creating hrb files on the fly and running them both in harbour and xharbour. In principle what I am looking for is something similar. Have some code as data somewhere and run it at runtime, instead of replacing the exe for every small modification.

PostPosted: Fri Nov 02, 2007 8:40 am
by Antonio Linares
This is a simple test. Please have a copy of harbour.exe where you run this:

test.prg
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   Compile( "another.prg" )

   __HrbRun( "another.hrb" )
   
   MsgInfo( "done" )

return nil

function Compile( cPrgName )

   WinExec( "harbour.exe " + cPrgName + " /n /gh", 0 )
   
   while ! File( cFileNoExt( cPrgName ) + ".hrb" )
      SysRefresh()
   end   
   
return nil   

Another.prg
Code: Select all  Expand view
function DontNameThisMain()

   MsgInfo( "Hello world!" )

return nil

Please notice that Harbour users don't need to keep an external harbour.exe as they can use hb_CompileBuf() that compiles from the application itself

PostPosted: Fri Nov 02, 2007 8:44 am
by nageswaragunupudi
Thanks

Assuming that we precompiled a program is .hrb and stored it as data. We read the .hrb into a memory variable. How can we execute it direclty? ( without having .hrb file on disk ) ?

PostPosted: Fri Nov 02, 2007 8:46 am
by Antonio Linares
NageswaraRao,

Just copy the data to a temporal external file:

MemoWrit( "test.hrb", cHrbData )

later on, erase it:

FErase( "test.hrb" )

PostPosted: Fri Nov 02, 2007 8:50 am
by Antonio Linares
My mistake, you can directly execute it from memory too :-)

__HrbRun( MemoRead( "another.hrb" ) )

PostPosted: Fri Nov 02, 2007 9:03 am
by nageswaragunupudi
Yes. This is better .. Thanks

PostPosted: Fri Nov 02, 2007 9:17 am
by nageswaragunupudi
I have tested with xharbour. In xharbour __hrbrun requires the filename as parameter. it looks like __hrbrun calls __hrbload with the file name. now if _hrbrun uses __hrbload to load the hrb file into memory, then what is the function that executes the code in the memory ? i guess we need to use that function to execute code in memory