Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP OLE CLASS with errors
Message
 
À
30/05/2012 14:23:33
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows 7
Divers
Thread ID:
01544802
Message ID:
01544978
Vues:
64
Victor,

90% of the time for this error the problem is ON ERROR firing when THIS is not in scope. You can't have an ON ERROR statement with THIS in it because THIS will not be in scope if a some child operation or native VFP function throws an error.

Either use a global var or better yet don't use ON ERROR at all - use TRY/CATCH which localizes your error handling.

+++ Rick ---

>Hello All:
>I have this VFP OLE class
>
>Define Class bIRexGenerador As Session OlePublic
>
>DataSession = 2 && Private Session
>
>PROCEDURE Generar
>
>PARAMETERS formatfile, outputfile,lclosefile,lsaveConfig,lAllowUserInteraction
>	SET DELETED ON
>	*!*	CLEAR ALL
>	*!*	RELEASE ALL
>	SET safety off
>	*SET EXCLUSIVE ON
>	SET EXCLUSIVE OFF
>	CLOSE ALL
>
>	lcOldError = ON("ERROR")
>	runId=SYS(2015)
>	logId=0
>	ON ERROR this.catchError()
>	#include EXCEL.H
>	[code]
>	
>ENDPROC
>		
>FUNCTION logs
>	LPARAMETERS x
>		IF ! ISNULL(oErr) AND TYPE("oErr") = "O" 
>		  IF !hayError
>		      ErrorEncontrado = "Error"+STR(oErr.ErrorNo)+[  LineNo: ] + STR(oErr.LineNo) +[  Message: ] + oErr.Message +[  Procedure: ] + oErr.Procedure +[  Details: ] + oErr.Details +[  StackLevel: ] + STR(oErr.StackLevel) +[  LineContents: ] + oErr.LineContents +[  UserValue: ] + oErr.UserValue 
>		  ENDIF
>	    ELSE
>		  IF !hayError    
>	    	  ErrorEncontrado =""
>	      ENDIF
>	      
>	    ENDIF
>	     
>		**INSERT INTO log VALUES (x, DATETIME(), linea,user, formatfile, outputfile, ErrorEncontrado)
>		INSERT INTO log VALUES (x, DATETIME(), fcRow,"Demo", formatfile, outputfile, ErrorEncontrado,RunId,LogId)
>		logId=LogId+1
>		hayError=.F.
>		**? x 
>	RETURN .t.
>
>ENDfunc 
>
>
>FUNCTION GetSheet
>	LPARAMETERS wbName,oXcel
>	Encontrado=.f.
>	FOR i=1 TO oXCEL.worksheets.Count
>		IF UPPER(oXcel.worksheets(i).Name) = UPPER(wbName)
>			Encontrado=.T.
>			RETURN oXcel.worksheets(i)
>		ENDIF
>	ENDFOR
>	oXcel.worksheets.ADD
>	xlSheet = oXcel.activesheet
>	xlSheet.NAME = wbName
>
>	RETURN xlSheet 
>ENDfunc
>
>FUNCTION valor
>	LPARAMETERS x
>	retval=""
>	IF !ISNULL(x)
>		DO case
>			CASE TYPE("x")="C"
>				retval=x
>			CASE TYPE("x")="N"
>				retval=STR(x)
>		ENDCASE
>	ENDIF
>	RETURN retval
>ENDfunc
>
>PROCEDURE CatchError
>	hayError=.t.
>	ErrorEncontrado =  'error #' + transform( error() ) + ': "' + message() + '"' + 'program:  ' + Program( Program(-1)-1) + 'line #' + transform( lineno() ) + ":  " + message(1)
>	=this.logs(errorencontrado)
>	RETURN
>ENDPROC
>
>ENDDEFINE
>
>
>
>It compiles and instantiates without error
>When I use it the generar proc get this error:
>"This can only be used in a method"
>
>Any help?
>
>Thanks in advance
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform