call a String as Function

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2108
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

call a String as Function

Post by AUGE_OHR »

hi,

i try to re-write a CLASS to FUNCTION

Code: Select all

   cFunc := "c" + cRet + "()"
   cRet := &cFunc

FUNCTION cStartup
return CSIDL_STARTUP                    // Start Menu\Programs\Startup
Error BASE/1001 Undefined function: CSTARTUP
Called from CSTARTUP(0)
Called from DOMYSYSACTION(333)
Called from (b)FUNCSYSFOLDER(284)
Called from _DOCONTROLEVENTPROCEDURE(6038)
Called from EVENTS(2011)
Called from DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(5699)
Called from FUNCSYSFOLDER(298)
Called from PREFUNCSYSFOLDER(3434)
Called from (b)MAIN(229)
Called from _DOCONTROLEVENTPROCEDURE(6038)
Called from EVENTS(824)
Called from DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(5699)
Called from MAIN(595)
so how to use a Macro to call a Function :idea:
have fun
Jimmy
User avatar
gfilatov
Posts: 1101
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: call a String as Function

Post by gfilatov »

AUGE_OHR wrote: Wed Jan 29, 2020 4:56 am hi,
...
so how to use a Macro to call a Function :idea:
Hi Jummy,

Please try the following code:

Code: Select all

cFunc := "c" + cRet + "()"
cRet := Eval( hb_macroBlock( cFunc ) )
HTH :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
AUGE_OHR
Posts: 2108
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: call a String as Function

Post by AUGE_OHR »

hi,
gfilatov wrote: Wed Jan 29, 2020 7:27 am Please try the following code:

Code: Select all

cFunc := "c" + cRet + "()"
cRet := Eval( hb_macroBlock( cFunc ) )
Ahhhh ... use a Codeblock and EVAL() it, THX
have fun
Jimmy
User avatar
mol
Posts: 3817
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: call a String as Function

Post by mol »

Code: Select all

cFunc := "{||" +    "c" + cRet + "()"     +"}"
cRet := Eval( &cFunc  )
do the same
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: call a String as Function

Post by KDJ »

Another way is to use @ operator for get reference to the function:

Code: Select all

sFunc := &("@c" + cRet + "()")
cRet := sFunc:exec(param1, param2, ...)
User avatar
Anand
Posts: 596
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

Re: call a String as Function

Post by Anand »

mol wrote: Wed Jan 29, 2020 8:08 pm

Code: Select all

cFunc := "{||" +    "c" + cRet + "()"     +"}"
cRet := Eval( &cFunc  )
do the same
I use this technique from Clipper time.

Regards,

Anand
Regards,

Anand

Image
User avatar
AUGE_OHR
Posts: 2108
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: call a String as Function

Post by AUGE_OHR »

hi,

thx for Answer.
i simple have not think about Codeblock which is more Powerfull
have fun
Jimmy
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: call a String as Function

Post by PeteWG »

Perhaps,

Code: Select all

cFunc := 'c'+cRet
cRet := hb_execFromArray( cFunc )
or

Code: Select all

cRet := hb_execFromArray( cFunc, {param1, param2, ...} )
or

Code: Select all

cRet := hb_execFromArray( {cFunc, param1, param2, ...} )
seems to be a good alternative, since it's quite simpler and I guess much faster.

P.S.: Please note that this function supports, also, some other syntaxes, (see Changelog.txt),
but the above is enough for the occasion, I think.

regards,
Pete
Post Reply