Saving arrays & codeblocks

Saving arrays & codeblocks

Postby HunterEC » Wed Jun 11, 2008 8:24 pm

Is there a way to save arrays & codeblocks to restore them later. I'm trying to save report filters.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42125
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby xProgrammer » 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
User avatar
xProgrammer
 
Posts: 464
Joined: Tue May 16, 2006 7:47 am
Location: Australia

Postby xProgrammer » 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
User avatar
xProgrammer
 
Posts: 464
Joined: Tue May 16, 2006 7:47 am
Location: Australia

Postby quique » Thu Jun 12, 2008 10:52 pm

with xharbour

Code: Select all  Expand view  RUN
   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
User avatar
quique
 
Posts: 408
Joined: Sun Aug 13, 2006 5:38 am

Postby xProgrammer » 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).

Code: Select all  Expand view  RUN
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:

Code: Select all  Expand view  RUN
MsgInfo( sTransfer )


Also worked with

Code: Select all  Expand view  RUN
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
User avatar
xProgrammer
 
Posts: 464
Joined: Tue May 16, 2006 7:47 am
Location: Australia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 55 guests