Gregory, I really liked your method and used it in my wrapper class that calls my UDF. I didn't use this within a form. I just used your method of executing the ON ERROR setting from within an Error() event.
It took me a while to figure out what you meant and what your example was doing, but I get it now. It seems to work nicely. Basically, I create a class that has two methods. One is the Error() event. The other is a method that calls my original UDF. After I create the object, I call the second method, which calls my UDF. When an error occurs in the UDF the Error event "macro's" the command that is returned from ON("ERROR"). That is slick! I'm so glad there is an easy and quick way to keep my existing UDF's in tact without major changes. Thanks a lot.
For anyone's reference, here is the code I add to the top of my UDF's:
----------------------------------
Function myfunc
o= CREATEOBJECT("myfunc")
o.myfunc(m.tcParm)
RETURN
*/////////////////////////////
DEFINE CLASS myfunc as Custom
**********
function myfunc
* this calls the original UDF
PARAMETERS m.tcParm
DO myfunc_ WITH m.tcParm
ENDFUNC
**********
PROTECTED function Error(m.tnError, m.tcMethod, m.tnLine)
* Error event gets called on any Errors (ON ERROR's are ignored).
LOCAL m.lcOnErr
m.lcOnErr= ON("error")
IF NOT EMPTY(m.lcOnErr)
&lcOnErr
ENDIF
* put some code here to handle any errors in case an ON ERROR isn't set.
ENDFUNC
ENDDEFINE
*////////////////////////////
PROCEDURE myfunc_ && this was the original UDF. Added an '_' to rename it.
PARAMETERS m.tcParm
* original program continues from here.
----------------------------------
>
>Mark,
>
>For what it is worth, this is the way I do it with forms
>
>normal on error : ON ERROR Error_(Error(), Program(), LineNo() )
>
>which starts with
>
>procedure Error_(nError, _program, _lineno )
>
>
>form.Error routine
>
>LPARAMETERS nError, _program, _lineno
>
>this.LockScreen = FALSE
>assert nError==Error()
>private __Object_with_Error__
>private __LineNoPassed__
>
>__Object_with_Error__ = this
>__LineNoPassed__ = _lineno
>
>
>local s
>s = on('error')
>&s
>
>release __Object_with_Error__, __LineNoPassed__
>
>
>In the error routine I test for the existance of __Object_with_Error__
>
>so the following routine works as expected, even in a form
>
>
>private HadError
>HadError = FALSE
>local sError
>sError = on('Error')
>on Error HaddError = TRUE
>
>use SomeTable excl
>on error &sError
>
>if( HadError )
>
>else
>
>
>endif
>