Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning from a class method on error.
Message
From
07/12/2001 16:23:39
 
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00591378
Message ID:
00591467
Views:
26
OK, that is what I felt was happening. I do want to process the errors in the component. What I do is I load .cErrorTxt with messages and return .F. or -1 to the Add method. The add method then calls the form's error method to display the getkey.cErrorTxt message.

OK I will cobble up my getkey.genkey method to check for text in the cErrorTxt property a million times. Then if there is something there I can return(.F. or -1) from the genkey method. It's a total pain but if it has to be done, it has to be done.

Thanks so much for your help

Terry

>Unless you are testing for an error condition throughout the GenKey method, there is no elegant way to return back to the Form.Add method. By default, once an error is processed, code execution continues at the next line after the one that caused the error. During your testing, if you find places that could cause an error, then you should follow that line with a test of your error flag. If the flag is true, the return and abort further execution of code in that method. If you do not want to do that, in the Form.Add, their is a most simplistic approach:
>lcOnError = on('error')
>on error return -1
>lnRetVal = Form1.cstGetKey.GenKey( "TableName" )
>on error &lcOnError
>if lnRetVal < 1
>   ** something bad happened
>   return
>endif
>However, this effectively end any ability to log and process any errors. If you do not care why this method failed, then this could be a workable solution for you.
>
>>I am using VFP 6 on 9x & 2000 machines. I designed a component GetKey that exposes a method GenKey designed to return Primary Key integers for my tables to use. I have setup an error routine to display errors I catch by calling the standard error method (that I modified) to trap -1 errors. I wish to be able to return to the calling program from that routine. I tried RETURN TO MASTER and I tried scanning the PROGRAM() programs and returning to Formxxx.Add but both failed. It kept returning to the next line in the local method.
>>
>>
>>So, here is the scenario:
>>
>>Form1 is running its Add method.
>>
>>That method calls Form1.cstGetKey.GenKey( "TableName" ) where tablename is the name of the table to generate a key for.
>>
>>Somewhere in the middle of the routine an error occures causing Form1.cstGetKey.Error(-1,mymessage,0) to fire.
>>
>>From there I want to return to Form1.Add() without further execution of the GenKey method. This shouldn't be a problem but I must be dense because I can't find the solution.
>>
>>Thanks in advance
>>
>>Terry
It is impossible to make programs idiot proof. Idiots are too cleaver.

MCP( Tcp/Ip )
Previous
Reply
Map
View

Click here to load this message in the networking platform