Page 1 of 1

How to determine a function existance

PostPosted: Wed Mar 22, 2006 11:50 am
by Vladimir Grigoriev
Hi
How to determine in Clipper program that a specified by a user function (for example through GET command) exists?
I.e. a user inputs a macro expression containing function name &SomeUDF and there is a need to determine does exist a function with name SomeUDF() or does not.
Vladimir Grigoriev

PostPosted: Wed Mar 22, 2006 12:23 pm
by Antonio Linares
Vladimir,

You may use Type( "FunctionName()" ) or better, Type( cExpression )

PostPosted: Thu Mar 23, 2006 9:46 am
by Vladimir Grigoriev
Antonio
Yesterday I tested a simple code and got the following results.

Code: Select all  Expand view
PROCEDURE MAIN()

? TYPE( "DEFINED()" ), TYPE( "2 + DEFINED()" )
? TYPE( "DEFINED() + ABS()" ), TYPE( "ABS()" )
? TYPE( "UNDEFINED()" ), TYPE( "2 + UNDEFINED()" )
? TYPE( "ABS() + UNDEFINED()" )

RETURN

FUNCTION DEFINED()
RETURN ( NIL )

UI UI UE UE U U UE

The last result "UE" destroys all concept to use TYPE( cExp ).

Vladimir Grigoriev

PostPosted: Fri Mar 24, 2006 8:27 am
by Antonio Linares
Vladimir,

It looks ok to me, as there is an undefined function in the expression.

PostPosted: Fri Mar 24, 2006 1:59 pm
by Vladimir Grigoriev
And you consider that TYPE( "ABS()" ) and ? TYPE( "ABS() + UNDEFINED()" ) both return "UE" is correct?

Vladimir Grigoriev

PostPosted: Wed Apr 05, 2006 8:44 pm
by Badara Thiam
Type() return the type of an expression by evaluate the expression.

You want to know if a function is linked in your executable ?
In this case, you can use Error system to intercept the error
returned if you do something like this :

************
function Test()
************
local cFunction := "MyFunc"
begin sequence
&(cFunction)()
end


When a function is not present in the exe, the error number
is always the same...


Regards,

PostPosted: Thu Apr 06, 2006 8:58 am
by Vladimir Grigoriev
I did not test but can be a such situation that BEGIN SEQUENCE will intercept an error which occured inside MyFunc() and wil be difficult to distinguish if the error is generated by the absence of the function or by the function itself?

PostPosted: Thu Apr 06, 2006 9:07 am
by Antonio Linares
Vladimir,

You may also modify Clipper errorsys and check for "undefined function" error.

PostPosted: Thu Apr 06, 2006 9:12 am
by Vladimir Grigoriev
This is an idea! It need to be tested.