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