Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Returning from a class method on error.
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00591378
Message ID:
00592109
Vues:
25
Yes, I am aware that a class Error method, if one exists and has code in it, takes precedence over any ON ERROR error handler. So, yes an ON ERROR RETURN -1, could work if no ERROR method existed in the form being called.

>Hi Mark,
>
>I found it by myself, though it's a well known fact, that on error would not work, if form has its own Error message. For instance, I have a procedure called OpenTble, which does:
>on error lnError = error()
>use MyTable...
>on error &lcOldError
>
>However, I found that it doesn't work on the form with Error method, so it gives me an error lately, when I tried to access this table... Something to watch out..
>
>>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
Mark McCasland
Midlothian, TX USA
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform