Convert

Convert

Postby Natter » Wed Sep 06, 2023 12:24 pm

Hi,

I need to convert a block of code ({||}) to a string. How can I do this?
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: Convert

Postby nageswaragunupudi » Wed Sep 06, 2023 1:30 pm

If the purpose is to save the string and restore later for execution:
Code: Select all  Expand view  RUN
  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
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Convert

Postby karinha » Wed Sep 06, 2023 2:02 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7831
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Convert

Postby Natter » Wed Sep 06, 2023 2:13 pm

Thanks !
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: Convert

Postby nageswaragunupudi » Wed Sep 06, 2023 3:15 pm

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Convert

Postby Otto » Wed Sep 06, 2023 6: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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6334
Joined: Fri Oct 07, 2005 7:07 pm

Re: Convert

Postby nageswaragunupudi » Thu Sep 07, 2023 5: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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Convert

Postby hua » Thu Sep 07, 2023 6:46 am

I used cMimeEnc() instead of strtohex()
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 78 guests