How to determine a function existance

Post Reply
Vladimir Grigoriev
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow
Contact:

How to determine a function existance

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Vladimir,

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

Antonio Linares
www.fivetechsoft.com
Vladimir Grigoriev
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow
Contact:

Post by Vladimir Grigoriev »

Antonio
Yesterday I tested a simple code and got the following results.

Code: Select all

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Vladimir,

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

Antonio Linares
www.fivetechsoft.com
Vladimir Grigoriev
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow
Contact:

Post by Vladimir Grigoriev »

And you consider that TYPE( "ABS()" ) and ? TYPE( "ABS() + UNDEFINED()" ) both return "UE" is correct?

Vladimir Grigoriev
User avatar
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

Post 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,
Badara Thiam
http://www.icim.fr
Vladimir Grigoriev
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow
Contact:

Post 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?
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Vladimir,

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

Antonio Linares
www.fivetechsoft.com
Vladimir Grigoriev
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow
Contact:

Post by Vladimir Grigoriev »

This is an idea! It need to be tested.
Post Reply