FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Convert
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Convert
Posted: Wed Sep 06, 2023 12:24 PM
Hi,

I need to convert a block of code ({||}) to a string. How can I do this?
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Convert
Posted: Wed Sep 06, 2023 01:30 PM
If the purpose is to save the string and restore later for execution:
Code (fw): Select all Collapse
   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
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Convert
Posted: Wed Sep 06, 2023 02:02 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Convert
Posted: Wed Sep 06, 2023 02:13 PM

Thanks !

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Convert
Posted: Wed Sep 06, 2023 03:15 PM

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

Regards



G. N. Rao.

Hyderabad, India
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Convert
Posted: Wed Sep 06, 2023 06:39 PM

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

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Convert
Posted: Thu Sep 07, 2023 05:12 AM
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
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Convert
Posted: Thu Sep 07, 2023 06:46 AM

I used cMimeEnc() instead of strtohex()

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion