Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need advice on error handling
Message
 
À
11/10/2000 12:21:56
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00427900
Message ID:
00427955
Vues:
14
>One of my Forms needs to open a couple of tables on the network exclusive, but other users might have some of these tables open else where and I am getting an error. What I would like is to catch the error , report that this operation needs to be run Sigle User and close the form again and back to the menu. Can this be done. I suppose I need to catch the error in the forms error event, but I am unable to stop the process and the close the form. I am getting the File Open dialog box.

To do this I have a method that will put a table name into the lcfiletotest (a dbf) to see if I can take it exclusively. The following will trap the error and report back to the status. HTH
* Lets build our command that we can then send to the oCheck.CheckCommand method
LOCAL lcUseCommand, loCheck, lErrorFlag
lcUseCommand = 'USE '+ALLTRIM(lcFileToTest)+' EXCLUSIVE'
loCheck = NEWOBJECT('WasError','WasError.PRG')
lErrorFlag = loCheck.CheckCommand(lcUseCommand)
loCheck.Release()

IF lErrorflag
  * We got the table exclusive so lets close it
  * and return
  USE
  lnReturnValue = 2
ELSE
  * We could not get the table exclusive
  lnReturnValue = 1
ENDIF

SELECT(lnSelectAreaSave)

IF NOT EMPTY(lcSaveDataBase)
  SET DATABASE TO (lcSaveDataBase)
ENDIF

RETURN lnReturnValue
The waserror.prg holds:
* WasError.PRG
* Example: oCheck = NEWOBJECT('WasError','WasError.PRG')
*     IsSuccess = oCheck.CheckCommand('USE MyTable EXCLUSIVE')
*     oCheck.Release()
*
* Class to determine if a command results in an error
DEFINE CLASS WasError AS Relation
   NoError = .T.          && Flag when there's an Error.
   ErrorNumber = 0
   ErrorMessage = ''

   PROCEDURE CheckCommand
      LPARAMETERS Command
         THIS.NoError = .T.
         &Command.
         RETURN THIS.NoError
      ENDPROC

   PROCEDURE Error
   LPARAMETERS nError, cMethod, nLine
      DEBUGOUT STR(nError) + " " + MESSAGE()
      WITH This
         .NoError = .F.
         .ErrorNumber = m.nError
         .ErrorMessage = MESSAGE()
      ENDWITH
      RETURN 
   ENDPROC

   PROCEDURE Release
      RELEASE THIS
   ENDPROC

ENDDEFINE
Bret Hobbs

"We'd have been called juvenile delinquents only our neighborhood couldn't afford a sociologist." Bob Hope
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform