Convert

Post Reply
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Convert

Post by Natter »

Hi,

I need to convert a block of code ({||}) to a string. How can I do this?
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Convert

Post by nageswaragunupudi »

If the purpose is to save the string and restore later for execution:

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 )
 
But, this works with xHarbour but not with Harbour.
With Harbour, no errors but HB_Serialize() returns a NULL string.
Regards

G. N. Rao.
Hyderabad, India
User avatar
karinha
Posts: 7932
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: Convert

Post by karinha »

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: Convert

Post by Natter »

Thanks !
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Convert

Post by nageswaragunupudi »

ValToPrg() and ValToPrgExp() are not useful for Objects and Codeblocks.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Otto
Posts: 6403
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 22 times
Been thanked: 2 times
Contact:

Re: Convert

Post by Otto »

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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Convert

Post by nageswaragunupudi »

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
Even to encode into Json, we first need to convert the codeblock into a "text" string.
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
hua
Posts: 1075
Joined: Fri Oct 28, 2005 2:27 am
Has thanked: 1 time
Been thanked: 1 time

Re: Convert

Post by hua »

I used cMimeEnc() instead of strtohex()
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
Post Reply