hb_hrbRun and some functions inside ...

hb_hrbRun and some functions inside ...

Postby Rimantas » Mon Feb 20, 2012 5:40 pm

Hi ,

Antonio , how to run in the same script some functions ? This is possible ? I did through script mdi child window with xbrowse and buttonbar . Buttonbar's buttons direct to function navigate_keys( VK_F5 ) ( as a sample ) . The same is in mdi child description - oWnd:bKeyDown := { | nKey, nFlags | navigate_key( nKey ) } ... In both situations - pressing needfull key on mdi child or pressing buttonbar I'm getting "Undefined function NAVIGATE_KEY" ... I tried REQUEST NAVIGATE_KEY in the prg ( script ) , the same bad result ... :( .

At this moment I'm seeing that prg as script can run only one single function inside prg . Maybe some functions can be running in a script with other compiler options ?

Many thanks in advance !
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: hb_hrbRun and some functions inside ...

Postby Antonio Linares » Tue Feb 21, 2012 12:47 am

Rimantas,

function navigate_keys( VK_F5 )


There is a typo in the name (missing "s"), check it

oWnd:bKeyDown := { | nKey, nFlags | navigate_key( nKey ) }
regards, saludos

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

Re: hb_hrbRun and some functions inside ...

Postby Rimantas » Tue Feb 21, 2012 4:53 am

Antonio Linares wrote:Rimantas,

function navigate_keys( VK_F5 )


There is a typo in the name (missing "s"), check it

oWnd:bKeyDown := { | nKey, nFlags | navigate_key( nKey ) }


No , Antonio , in mine source the function name is the same . I did mistake only here , describing problem .
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: hb_hrbRun and some functions inside ...

Postby Antonio Linares » Tue Feb 21, 2012 8:52 am

Rimantas,

Using FWH\samples\scripts.prg, this example works fine:

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

function Test()

   Another()

return nil

function Another()

   OneMore()

return nil

function OneMore()

   MsgInfo( "Hello from OneMore()" )

return nil
 
regards, saludos

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

Re: hb_hrbRun and some functions inside ...

Postby Rimantas » Tue Feb 21, 2012 11:39 am

Antonio Linares wrote:Rimantas,

Using FWH\samples\scripts.prg, this example works fine:

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

function Test()
   Another()
return nil

function Another()
   OneMore()
return nil

function OneMore()
   MsgInfo( "Hello from OneMore()" )
return nil
 


I can confirm that is working . Let describe the problem better . I mentioned , mine script create mdi child with xbrowse and button bar . Also I can say that buttonbar of mdi child window is in other function in the same prg . But all other functions in the same prg will became "undefined" after ACTIVATE WINDOW oWnd ... I don't know really , but it can be related to hb_hrbRun / hb_hrbDo lifetime or something similar ... Now prg as script run :

Code: Select all  Expand view

function Run_prg( cPrg )
local oRun
local lRet     := .t.
local lCompile := .f.
local dPrdDate, dHrbDate
local cPrgTime, cHrbTime
local cTxtFile, cLine, nFrom := 1
local cLog := cProgr_logai + "\hcmp" + alltrim( cVart_id ) + ".log"
local nHrb_hdl

if !jungtis_serveris()
   return( .f. )
endif

if file( cProgr_kelias + cPrg + ".prg" )
   TRY
      if File( cLog )
         ferase( cLog )
      endif
      FReOpen_Stderr( cLog, "w" )
      oRun     := HB_compilebuf( HB_ARGV( 0 ), cProgr_kelias + cPrg + ".prg", "-n", "-i" + cPagr_kelias + "fwh_incl;" + cPagr_kelias + "hrb_incl" )
      cTxtFile := MemoRead( cLog )
      if empty( cTxtFile  )
         if !Empty( oRun )
            BEGIN SEQUENCE
               bOldError = ErrorBlock( { | o | DoBreak( o ) } )
[color=#FF0000]              
               nHrb_hdl := hb_hrbload( oRun )
               hb_hrbDo( nHrb_hdl )
               hb_hrbunload( nHrb_hdl )
[/color]              
              //hb_HrbRun( oRun )
            END SEQUENCE
            ErrorBlock( bOldError )
          else
           MsgInf( "Can't to generate file ... :-( ", 2 )
         endif
       else
         WinExec( "Notepad " + cLog )
      endif
   CATCH e
     lRet := .f.
   END
  else
   MsgInf( "Can't to find file - " + cProgr_kelias + cPrg + ".prg ...", 2 )
   lRet := .f.
endif
if !empty( oRun )
   oRun := NIL
endif
return( lRet )
 


In red - script run and then unload . The engine of scripts nothing know about mdi child window inside script ... And , as I mentioned , all other functions in script became "undefined" . Maybe exist other way to run script with windows ?
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: hb_hrbRun and some functions inside ...

Postby Antonio Linares » Tue Feb 21, 2012 11:51 am

Rimantas,

As soon as you call hb_hrbunload( nHrb_hdl ) then you "unload" the scripts functions.

You have to call hb_hrbunload( nHrb_hdl ) once you are done with those functions and you will no longer use those functions again.
regards, saludos

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

Re: hb_hrbRun and some functions inside ...

Postby Rimantas » Tue Feb 21, 2012 12:18 pm

Antonio Linares wrote:Rimantas,

As soon as you call hb_hrbunload( nHrb_hdl ) then you "unload" the scripts functions.
You have to call hb_hrbunload( nHrb_hdl ) once you are done with those functions and you will no longer use those functions again.


The problem is that , I commented all "unload" places .
// hb_hrbUnload( nHrb_hdl ) and // oRun := NIL and etc. .
The same result .

Tested only hb_hrbRun( oRun ) , then with hb_hrbDo( nHrb_hdl ) .
Nothing changes , "undefined" after ACTIVATE WINDOW ...
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: hb_hrbRun and some functions inside ...

Postby Antonio Linares » Tue Feb 21, 2012 12:59 pm

Rimantas,

Please provide me a small script example to reproduce it here, thanks
regards, saludos

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

Re: hb_hrbRun and some functions inside ...

Postby Rimantas » Tue Feb 21, 2012 5:11 pm

Antonio Linares wrote:Rimantas,

Please provide me a small script example to reproduce it here, thanks


Of course , that I must did alreday .... :) Excuse .

Code: Select all  Expand view

#include "FiveWin.ch"
#include "xbrowse.ch"

static oWnd, oBrw

function script_mdiw()

USE ( "SALES" ) NEW ALIAS "SALES"

DEFINE WINDOW oWnd MDICHILD OF WndMain() TITLE "Script problem with MDI CHILD window"

@ 0, 0 XBROWSE oBrw OF oWnd ALIAS Alias() AUTOCOLS AUTOSORT LINES CELL

oBrw:CreateFromCode()
oWnd:oClient := oBrw

oWnd:bInit    := { || make_bar( oWnd ), oBrw:SetFocus() }
oWnd:bValid   := { ||  ( oBrw:cAlias )->( dbclosearea() ), .t. }
oWnd:bKeyDown := { | nKey, nFlags | wind_keyp( nKey ) }

oWnd:Activate( "NORMAL" )

return( NIL )

static function make_bar( oWnd )
local oBut[ 3 ], oBar

DEFINE BUTTONBAR oBar SIZE nButSiz, nButSiz OF oWnd TOP 3D
DEFINE CURSOR oBar:oCursor HAND

DEFINE BUTTON oBut[ 1 ] OF oBar FILE "c:\fwh\bitmaps\16x16\delete.bmp" ;
MESSAGE "Delete record - Del" ACTION wind_keyp( VK_DELETE )

DEFINE BUTTON oBut[ 2 ] OF oBar FILE "c:\fwh\bitmaps\16x16\search.bmp" ;
MESSAGE "Find - F9" ACTION wind_keyp( VK_F9 )

DEFINE BUTTON oBut[ 3 ] OF oBar FILE "c:\fwh\bitmaps\16x16\print.bmp" ;
MESSAGE "Print - F5" ACTION wind_keyp( VK_F5 )

return( NIL )

function wind_keyp( nKey )
MsgInfo( nKey )
return( NIL )
 


Simply run this code as script , it can be done and from your scripts sample in fwh\samples folder .
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: hb_hrbRun and some functions inside ...

Postby Rimantas » Tue Feb 21, 2012 5:59 pm

Antonio ,

It seems that something I found ... :) Maybe it's not clear , but working . I created 2 vars in the main prg : nMain_hrb and aHrb empty array . Now in excute section I added that :
Code: Select all  Expand view

               nMain_hrb      := hb_hrbload( oRun )
               hb_hrbDo( nMain_hrb )
               u := ascan( aHrb, { |x| x[ 1 ] == 0 } )
               if u == 0
                  aadd( aHrb, { nMain_hrb, oRun } )
                 else
                  aHrb[ u, 1 ] := nMain_hrb
                  aHrb[ u, 2 ] := oRun
               endif
 


Then added function in main prg :
Code: Select all  Expand view

function harb_unload( nHrb )
local u := ascan( aHrb, { |x| x[ 1 ] == nHrb } )
if u # 0
   hb_hrbUnload( nHrb )
   aHrb[ u, 1 ] := 0
   aHrb[ u, 2 ] := NIL
endif
return( NIL )
 


In script prg at the beginning of source I direccted : local nHrb := nMain_hrb
In bValid of oWnd added : oWnd:bValid := { || ( cwAlias )->( dbclosearea() ), harb_unload( nHrb ), .t. }

Now I can say that other functions are working with MDI Child enviroment . Some undoubts - it must be directed vars with values and unload of scripts ... :)

Maybe you can suggest more clear method ?
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: hb_hrbRun and some functions inside ...

Postby Antonio Linares » Wed Feb 22, 2012 9:22 pm

Rimantas,

It seems as a fine way to manage several loaded scripts :-)
regards, saludos

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 22 guests