How to determine a function existance

How to determine a function existance

Postby Vladimir Grigoriev » 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
Vladimir Grigoriev
 
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow

Postby Antonio Linares » Wed Mar 22, 2006 12:23 pm

Vladimir,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Vladimir Grigoriev » Thu Mar 23, 2006 9:46 am

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
Vladimir Grigoriev
 
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow

Postby Antonio Linares » Fri Mar 24, 2006 8:27 am

Vladimir,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Vladimir Grigoriev » Fri Mar 24, 2006 1:59 pm

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

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

Postby Badara Thiam » Wed Apr 05, 2006 8: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
User avatar
Badara Thiam
 
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France

Postby Vladimir Grigoriev » Thu Apr 06, 2006 8: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?
Vladimir Grigoriev
 
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow

Postby Antonio Linares » Thu Apr 06, 2006 9:07 am

Vladimir,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Vladimir Grigoriev » Thu Apr 06, 2006 9:12 am

This is an idea! It need to be tested.
Vladimir Grigoriev
 
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow


Return to FiveWin for CA-Clipper

Who is online

Users browsing this forum: No registered users and 3 guests