Saving arrays & codeblocks
Saving arrays & codeblocks
Is there a way to save arrays & codeblocks to restore them later. I'm trying to save report filters.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- xProgrammer
- Posts: 464
- Joined: Tue May 16, 2006 7:47 am
- Location: Australia
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
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
- xProgrammer
- Posts: 464
- Joined: Tue May 16, 2006 7:47 am
- Location: Australia
with xharbour
the codeblock only the program of generate can redo the codeblock
Code: Select all
local a,b,c,d,e
a := {"a", "b", "c" }
b := { || "quique" }
c := valtoprgexp( a )
d := valtoprgexp( b )
e := &d
wqout( &c )
? eval( e )
Saludos
Quique
Quique
- xProgrammer
- Posts: 464
- Joined: Tue May 16, 2006 7:47 am
- Location: Australia
With xHarbour (on Linux at least but I suspect Windows also) the following code runs as expected (but with the limitations discussed below).
The contents of SavedCode.txt were as follows:
Also worked with
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
Code: Select all
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
Code: Select all
MsgInfo( sTransfer )
Code: Select all
MsgInfo( DATE() )
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