FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Saving arrays & codeblocks
Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM

Saving arrays & codeblocks

Posted: Wed Jun 11, 2008 08:24 PM

Is there a way to save arrays & codeblocks to restore them later. I'm trying to save report filters.

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Saving arrays & codeblocks

Posted: Wed Jun 11, 2008 10:30 PM

You may use FWH ASave() and ARead() functions:

MemoWrit( "array.txt", ASave( aArray ) )

to load it, later on:

aArray = ARead( MemoRead( "array.txt" ) )

There is no way to save codeblocks to disk files, as local references get lost.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 464
Joined: Tue May 16, 2006 07:47 AM

Saving arrays & codeblocks

Posted: Thu Jun 12, 2008 12:57 PM

Hi HunterEC

Codeblocks can of course be saved in source form since in that form they are just character strings in a particular format. So if they are entered or generated in source form you can save the source and compile them from that source for use at a later date. If it is an interactive reporting system you are developing my guess is they might well be obtainable in such form.

Check out HB_MacroCompile, HB_VMExecute, &( "{||" + cMacro + "}" )

I should note that this is not a line of coding I have had any call to use to date so my information is largely based on documentation alone.

Happy coding
xProgrammer

Posts: 464
Joined: Tue May 16, 2006 07:47 AM

Saving arrays & codeblocks

Posted: Thu Jun 12, 2008 10:02 PM

An addendum

One could (based on the documentation) actually store the compiled pcode - however this would potentially fail any time that the pcode specification changed and the application was recompiled.

Regards
xProgrammer

Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM

Saving arrays & codeblocks

Posted: Thu Jun 12, 2008 10:52 PM
with xharbour

   local a,b,c,d,e
   a := {"a", "b", "c" }
   b := { || "quique" }
   c := valtoprgexp( a )
   d := valtoprgexp( b )
   e := &d
   wqout( &c )
   ? eval( e )


the codeblock only the program of generate can redo the codeblock
Saludos

Quique
Posts: 464
Joined: Tue May 16, 2006 07:47 AM

Saving arrays & codeblocks

Posted: Fri Jun 13, 2008 12:24 PM
With xHarbour (on Linux at least but I suspect Windows also) the following code runs as expected (but with the limitations discussed below).

FUNCTION TestSavedCode()

LOCAL sSavedCode
LOCAL sPCode
PUBLIC sTransfer

sTransfer := "testing saved code"
sSavedCode := MemoRead( "SavedCode.txt" )
// MsgInfo( sSavedCode )
sPCode := HB_MacroCompile( sSavedCode )
// MsgInfo( "About to Execute" )
HB_VMExecute( sPCode )
// MsgInfo( "Done" )

RETURN nil


The contents of SavedCode.txt were as follows:

MsgInfo( sTransfer )


Also worked with

MsgInfo( DATE() )


The limitations I have found so far are:

1. I had to make sTransfer a PUBLIC variable, if the variable was declared LOCAL it was not found.

2. I couldn't get more than a single function. That is it would work as expected with either of the above functions in SavedCode.txt but not with both. There may well be a way to fix that directly but if not it would be a simple matter to read SavedCode.txt line by line and execute accordingly.

I tried doing the same thing using the macro operator to create a code block as per the xHarbour documentation but it didn't seem to work for me.

In summary there appears to be some capability at least to save a code block in source form and to compile and execute later from that saved text but there also appears to be some possible restrictions beyond what might be assumed from the xHarbour documentation.

I don't plan on doing any more testing in this area unless people still see an application for such capabilities and feel they need help.

Regards
xProgrammer

Continue the discussion