Hi,
I need to convert a block of code ({||}) to a string. How can I do this?
Convert
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: Convert
If the purpose is to save the string and restore later for execution:
But, this works with xHarbour but not with Harbour.
With Harbour, no errors but HB_Serialize() returns a NULL string.
Code: Select all | Expand
b := { || MsgInfo( "Good" ) }
Eval( b )
c := HB_Serialize( b )
? ValType( c ), Len( c ), STRTOHEX( c )
// save the string as hex and restore
b := HB_DeSerialize( c )
? Eval( b )
With Harbour, no errors but HB_Serialize() returns a NULL string.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- karinha
- Posts: 7932
- Joined: Tue Dec 20, 2005 7:36 pm
- Location: São Paulo - Brasil
- Been thanked: 3 times
- Contact:
Re: Convert
https://vivaclipper.wordpress.com/2012/ ... de-blocks/
http://www.pctoledo.com.br/forum/viewto ... =4&t=11979
Regards.
http://www.pctoledo.com.br/forum/viewto ... =4&t=11979
Regards.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: Convert
ValToPrg() and ValToPrgExp() are not useful for Objects and Codeblocks.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Otto
- Posts: 6403
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 22 times
- Been thanked: 2 times
- Contact:
Re: Convert
Dear Rao,
Just out of curiosity, I haven't really delved into the question yet. But would JSON encode and decode also be an option?
Best regards,
Otto
Just out of curiosity, I haven't really delved into the question yet. But would JSON encode and decode also be an option?
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: Convert
Even to encode into Json, we first need to convert the codeblock into a "text" string.Otto wrote:Dear Rao,
Just out of curiosity, I haven't really delved into the question yet. But would JSON encode and decode also be an option?
Best regards,
Otto
How?
The only function available is HB_Serialize( bBlock ) --> cBinaryString and then convert into text using STRTOHEX(), before we encode it as Json or directly save into a field.
Unfortunately, this function is working in xHarbour only and not in Harbour.
Even there the limitation is that the codeblock should not have any references to local/static variables and static functions.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India