Page 1 of 1 1
Topic Options
#15981 - 2002-01-10 06:28 PM Testing for the presence of a UDF
New Mexico Mark Offline
Hey THIS is FUN
****

Registered: 2002-01-03
Posts: 223
Loc: Columbia, SC
Is there a way to test for the presence of a particular UDF?

For instance, if I have a function like FMT() that may or may not call various UDF's, is there a way to test to make sure the particular UDF being called is present before trying to call it (and crashing the script)? This would allow for more graceful error handling.

Thanks,

New Mexico Mark

Top
#15982 - 2002-01-10 06:49 PM Re: Testing for the presence of a UDF
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hi Mark,

I had the same thoughts as you a while back, and also wondered if this would be a usefull feature (ie, for Ruud to include into a future release) ... my gut feeling is that NO, there is no way to do this (aside from actually reading and parsing the script yourself - which is obviously out of the question).

I had two ideas I thought might work ... since function return values are assigned using the function name itself, eg.


Function Add($n1,$n2)
$Add=$n1+$n2 ; <--- here
EndFunction

and since KiXtart does a pre-scan pass to cache UDF pointers, was thinking that the $Add variable itself would be defined as not "Empty" before-hand and that we could check for that before calling the function (ie, by using the vartype function) ... that doesn't work

Than I thought that maybe by cleverly using the execute function - we could test try a call to a function without actually causing a hard syntax error (script abort) and use the result of that somekind of conditional statement, like this (warning - this is non-working psuedo-code) :



If Execute("$=Add(1,2)") ; <--- If a softcall to this function works
$Result = Add(1,2) ; <--- do a hardcall to it
Else
?"Add function is not available"
EndIf

Hope maybe I've given you or someone else some food thought on this ... let's keep trying.

-Shawn

[ 10 January 2002: Message edited by: Shawn ]

Top
#15983 - 2002-01-10 06:51 PM Re: Testing for the presence of a UDF
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
one way that comes to mind, kinda of a kludge, but should work...

code:
$UDFfile = "test.kix"
$isUDF = "things"

shell '%comspec% /c type $UDFfile | find /i "function $isUDF" > nul'

if @error = 0
"Function $isUDF was found"
else
"Function $isUDF was NOT found"
endif



Bryce

[ 10 January 2002: Message edited by: Bryce ]

Top
#15984 - 2002-01-10 07:05 PM Re: Testing for the presence of a UDF
New Mexico Mark Offline
Hey THIS is FUN
****

Registered: 2002-01-03
Posts: 223
Loc: Columbia, SC
Hi Shawn:

Actually the internal KiXtart function approach might be best. As you said, KS does a prepass scan for UDF's. If these are identified by name, they must be accessible to other parts of the program.

I guess this is a Ruud question, but why not an ExistUDF() function?

New Mexico Mark

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1452 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.057 seconds in which 0.029 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org