FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for CA-Clipper How to determine a function existance
Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
How to determine a function existance
Posted: Wed Mar 22, 2006 11:50 AM

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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to determine a function existance
Posted: Wed Mar 22, 2006 12:23 PM

Vladimir,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
How to determine a function existance
Posted: Thu Mar 23, 2006 09:46 AM
Antonio
Yesterday I tested a simple code and got the following results.

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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to determine a function existance
Posted: Fri Mar 24, 2006 08:27 AM

Vladimir,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
How to determine a function existance
Posted: Fri Mar 24, 2006 01:59 PM

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

Vladimir Grigoriev

Posts: 160
Joined: Tue Oct 18, 2005 10:21 AM
How to determine a function existance
Posted: Wed Apr 05, 2006 08:44 PM

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
Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
How to determine a function existance
Posted: Thu Apr 06, 2006 08:58 AM

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?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to determine a function existance
Posted: Thu Apr 06, 2006 09:07 AM

Vladimir,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
How to determine a function existance
Posted: Thu Apr 06, 2006 09:12 AM

This is an idea! It need to be tested.

Continue the discussion