Having the name of a function, I would like to know if the function is
defined without testing it. Is it possible ?
Regards,
mathmax
cMacro := "TestFunc( nNumber )"
I would like to test if TestFunc exists before executing it. I don't
want to use a try-catch because I want to know if the function existe
before calling it.
simple do
type("FUNCNAME")
it will return
UI if the function exist, otherwise will return U if the function dont exist
Regards
Luiz
Doesn't work by my side. Always return U.
TYPE( "MINHAFUNC()" )
and
FUNCTION MINHAFUNC() // don´t be "static"
///...
RETURN NIL
<maximean...@gmail.com> escreveu na mensagem
news:1299aedc-346e-46a0...@m45g2000hsb.googlegroups.com...
PMJI
I believe that Clipper's TYPE actually macro-evaluates the
expression. Is it the same with xHarbour?
If so, wouldn't it present a problem for a function with STATIC
variables?
For example, if you test for an existence of the following function:
FUNCTION Test()
STATIC nNum:=0
RETURN ++nNum
TIA, Eugene
======================================================
On Jul 22, 8:27 am, "luiz Rafael Culik Guimaraes"
> I believe that Clipper's TYPE actually macro-evaluates the
> expression. Is it the same with xHarbour?
>
> If so, wouldn't it present a problem for a function with STATIC
> variables?
>
> For example, if you test for an existence of the following function:
>
> FUNCTION Test()
> STATIC nNum:=0
> RETURN ++nNum
Neither Clipper nor xHarbour evaluate (call) the function.
EMG
--
EMAG Software Homepage: http://www.emagsoftware.it
The EMG's ZX-Spectrum Page: http://www.emagsoftware.it/spectrum
The Best of Spectrum Games: http://www.emagsoftware.it/tbosg
The EMG Music page: http://www.emagsoftware.it/emgmusic
Also .-
if __DynsIsFun( __DynsGetIndex( 'TestFunc' ) )
HB_ExecFromArray( {'TestFunc', nNumber} )
else
? "Not exist TestFunc."
endif
Best regards,
Xavi
#pragma BEGINDUMP
#include <hbapi.h>
HB_FUNC( ISFUNCTION )
{
PHB_DYNS sym = hb_dynsymFindName(hb_parc(1));
hb_retl( sym ? hb_dynsymIsFunction( sym ) : 0);
}
#pragma ENDDUMP
then call
IsFunction("symbolname") -> .t. if the symbol exists and is a function
reference
Some internal needed, but this worked here.
The function expects a symbolic function name, so in your example you have
to call
IsFunction("TestFunc")
Best regards.
Maurizio la Cecilia
<maximean...@gmail.com> ha scritto nel messaggio
news:3b5894a0-ac26-41ff...@34g2000hsh.googlegroups.com...
"Maurizio la Cecilia" <m.lac...@libero.it> wrote in message
news:Haohk.31659$Ca.1...@twister2.libero.it...
About the docs reading, maybe something would be more accurately precised
as in doc/var.txt the Type() reference says:
* The data type of expression is checked by invoking a macro compiler
* and by evaluation of generated code (if there is no syntax errors).
and this is the description of the xHarbour Language Reference Guide:
"Type() is used to determine the data type of a macro expression by
evaluating or executing it with the macro operator. The expression is most
often the name of a dynamic memory variable, or a field variable."
You see, without reading the subsequent post i haved some doubt about the
way Type() works.
Regards.
"Ron Pinkas" <R...@xHarbour.com> ha scritto nel messaggio
news:g6548e$2rl$1...@aioe.org...
The desvription could be improved but the included sample clearly shows:
? Type( "Test()" ) // result: UI
? Type( "TestFunc()" ) // result: U
The answer posted by Luiz also provided the same info.
FWIW, my experience is that reports such as:
"Doesn't work by my side. Always return U."
Should not receive great weight when compared to detailed technical
responses.
Ron
Maurizio
"Ron Pinkas" <R...@xHarbour.com> ha scritto nel messaggio
news:g65f5h$n3t$1...@aioe.org...
With this example you test, "functions", "vars" and "expressions":
[CODE]
*************
function MAIN
*************
cls
? "Variável <var1> existe ?: ", ExpValid( "var1" )
private var1 := "1"
? "Variável <var1> existe ?: ", ExpValid( "var1" )
? "Expressão é valida <alltrim(var1)> ?: ", ExpValid( "alltrim(var1)" )
? "Expressão é valida <allllltrim(var1)> ?: ", ExpValid(
"allllltrim(var1)" )
? "A função existe <TESTE> ?: ", ExpValid( "TESTE()" )
? "A função existe <TESTE_1> ?: ", ExpValid( "TESTE_1()" )
? "A função existe <TESTE_2> ?: ", ExpValid( "TESTE_2()" )
return NIL
*****************
FUNCTION ExpValid( cExp )
*****************
local lOk := .T., xResult
local bError := ErrorBlock( { |e| ExpError( e, bError ) } )
cExp := alltrim(cExp)
BEGIN SEQUENCE
if !Empty( cExp )
lOk := .t.
xResult := &cExp
if !lOk
? "Tipo de expressão inválida."
endif
endif
RECOVER
lOk := .F.
END SEQUENCE
ErrorBlock( bError )
return lOk
************************
STATIC FUNCTION ExpError( e, bOldErr )
************************
if e:subSystem == "BASE"
if procname(7) = "ENTRADA" .or. procname(8) = "ENTRADA" .or.
procname(10)= "EDITAREF"
? e:descriptio +". Expressão Inválida."
endif
BREAK e
endif
return Eval( bOldErr, e )
**************
function TESTE
**************
? "Olá eu sou uma função PUBLICA (public)"
return NIL
***********************
static function TESTE_1
***********************
? "Olá eu sou uma função ESTÁTICA (static)"
return NIL
[ENDCODE]
Regards,
Rossine.
"Maurizio la Cecilia" <m.lac...@libero.it> escreveu na mensagem
news:EOthk.121232$FR.3...@twister1.libero.it...