Page 1 of 1

Extend Codeblock

Posted: Wed Jul 30, 2014 11:22 am
by cmsoft
Como puedo hacer para crear un Extend Codeblock, pero sacando el bloque de codigo desde un texto?

Code: Select all | Expand

#include "FiveWin.ch"
STATIC FUNCTION ExtendCodeBlock()
local bBloque, cBloque, i
   // Este código funciona bien  
   bBloque := { ||
                LOCAL i
                FOR i := 1 to 10
                   MSGINFO(STR(i,1))                                    
                NEXT i
                return nil
                }

   Eval(bBloque)
   // Este código funciona bien
   cBloque := "{|i| MsgInfo(i)}"
   bBloque := &(cBloque)
   // Esto da error
   Eval(bBloque,1)
   cBloque := "{|| "+CHR(10)+;
              "  LOCAL i "+CHR(10)+;
              "  FOR i := 1 to 10 "+CHR(10)+;
              "     MSGINFO(STR(i,1))  "+CHR(10)+;
              "  NEXT i "+CHR(10)+;
              "  return nil}"
   bBloque := &(cBloque)  
   Eval(bBloque)
   // Este da error
   cBloque := MemoRead( "func.prg")
   bBloque := &(cBloque)
   Eval(bBloque)    
return nil
 

Re: Extend Codeblock

Posted: Thu Jul 31, 2014 2:15 pm
by emotta_no
do it

viewtopic.php?f=3&t=25813&p=141241&hilit=hrbrun#p141241

Code: Select all | Expand



    function Run_prg( cPrg )
    local oHrb, cResult
    if !db_conn()
       return( NIL )
    endif
    if !file( cPrg + ".prg" )
       MsgAlert( "Nera tokio failo: " + cPrg + ".prg !" )
       return( NIL )
    endif

    FReOpen_Stderr( "run_prg.log", "w" )
    HB_Compile( "", cPrg + ".prg", "/n", "/gh", "-ID:\A\fwh\include", "-ID:\A\hrbg\include" )
    oHrb = HB_HRBLOAD( cPrg + ".hrb" )
    HB_HRBDO( oHrb )
    HB_HRBUNLOAD( oHrb )
    oHrb = NIL
    return( NIL )
     
 

Re: Extend Codeblock

Posted: Thu Jul 31, 2014 4:11 pm
by Antonio Linares
Usa la función de FWH Execute( cSourceCode [, params...] ) --> uReturnValue

Es la forma más simple de ejecutar código desde texto :-)

Tienes un ejemplo de uso en FWH\samples\FiveDBU.prg

Re: Extend Codeblock

Posted: Thu Jul 31, 2014 4:19 pm
by Antonio Linares

Re: Extend Codeblock

Posted: Thu Jul 31, 2014 5:29 pm
by emotta_no
This only works Harbour? For XHARBOUR what solution?

Re: Extend Codeblock

Posted: Thu Jul 31, 2014 9:11 pm
by cmsoft
Antonio, a partir de que versión de FiveWin está esa función? Yo tengo la 11.12 y no tengo esa funcion...

Re: Extend Codeblock

Posted: Fri Aug 01, 2014 6:03 am
by Antonio Linares
La función Execute() se añadió en FWH 12.07.

Esta función usa la líbreria hbcplr.lib de Harbour, la cual no existe en xHarbour, asi que sólo está disponible para los usuarios de Harbour.

Emota,

The only solution for xHarbour users is to migrate to Harbour :-)

Re: Extend Codeblock

Posted: Fri Aug 01, 2014 1:50 pm
by emotta_no
Thanks Antonio.. your solution is best. I can't to migrate for Harbour now because I use SQLRDD. I use this code for this solution...

oScript := __hrbLoad( cArquivo )
__hrbDo( oScript,aPar[1],aPar[2],aPar[3],aPar[4],aPar[5],aPar[6],aPar[7],aPar[8],aPar[9] )

Re: Extend Codeblock

Posted: Fri Aug 01, 2014 2:39 pm
by Antonio Linares
Emotta,

The really nice thing about function Execute() is that the whole process is done in memory, so no files are involved at all, no need to call an external compiler.

Its really nice :-)

Re: Extend Codeblock

Posted: Fri Aug 01, 2014 6:22 pm
by emotta_no
Thanks Antonio, I want to use Harbour... but now it's impossible.