grid problem

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

edk
Posts: 76
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 12 times
Been thanked: 24 times

Re: grid problem

Post by edk » Tue Feb 07, 2017 8:16 am

Hi Franco.
The problem arises when divided by zero or failed to block network access to the database or adding a record.
According to a source in the following cases: EG_ZERODIV, EG_OPEN, EG_APPENDLOCK.
It is important that these events NOT must be at GRID. They can occur anywhere in the program and then GRID will have blank rows, until you close a program.
It was reported on the forum: http://www.hmgforum.com/viewtopic.php?f ... =20#p43507
As he wrote Marek, you have to change ErrorSys.prg and rebuild hmg. Then rebuild own project.
You also do not change ErrorSys, You need add in your own project error handling.
At the beginning of the procedure MAIN:

Code: Select all

OrgErrorBlock := ErrorBlock( { | oError | FrancosError( oError ) } )
and at the end of project

Code: Select all

****************************
FUNCTION FrancosError( oError )
   LOCAL cMessage
   LOCAL cDOSError

   LOCAL n
   Local Ai
   Local lUsr:=.F.

   //Html Arch to ErrorLog
   LOCAL HtmArch, xText

   MEMVAR _HMG_SYSDATA
   #include "hmg.ch"
   #include "error.ch"
   #INCLUDE "COMMON.CH"
   
   // By default, division by zero results in zero
   IF oError:genCode == EG_ZERODIV
      RETURN 0
   ENDIF

   // Set NetErr() of there was a database open error
   IF oError:genCode == EG_OPEN .AND. ;
      oError:osCode == 32 .AND. ;
      oError:canDefault
      NetErr( .T. )
      RETURN .F.
   ENDIF

   // Set NetErr() if there was a lock error on dbAppend()
   IF oError:genCode == EG_APPENDLOCK .AND. ;
      oError:canDefault
      NetErr( .T. )
      RETURN .F.
   ENDIF

   // _HMG_SYSDATA [ 347 ] := .F. <-I think that this line is not needed at all   
   
   HtmArch := Html_ErrorLog()
   cMessage := ErrorMessage( oError )
   IF ! Empty( oError:osCode )
      cDOSError := "(DOS Error " + LTRIM( STR( oError:osCode ) ) + ")"
   ENDIF

   IF ! Empty( oError:osCode )
      cMessage += " " + cDOSError
   ENDIF
   Html_LineText(HtmArch, '<p class="updated">Date:' + Dtoc(Date()) + "  " + "Time: " + Time() )
   Html_LineText(HtmArch, cMessage + "</p>" )
   n := 2
   ai = cmessage + CHR(13) + CHR (10) + CHR(13) + CHR (10)
   WHILE ! Empty( ProcName( n ) )
      xText := "Called from " + ProcName( n ) + "(" + ALLTRIM( STR( ProcLine( n++ ) ) ) + ")" +CHR(13) +CHR(10)
      ai = ai + xText
      Html_LineText(HtmArch,xText)
   ENDDO
   Html_Line(HtmArch)

   lUsr:=ShowError(ai, (oError:canRetry), (oError:canDefault))

   *QUIT

   RETURN lUsr

// [vszakats]

*******************************************
Function ShowError ( ErrorMesssage , lRetry, lDefault)
********************************************
Local nRetMsg, nMilliseconds := 30000 //30 sec
Local nTypeIconButton
	#include "i_MsgBox.ch"
	
	DO CASE
		CASE !lRetry .AND. !lDefault
			nTypeIconButton := MB_OK
		CASE lRetry .AND. lDefault
			nTypeIconButton := MB_ABORTRETRYIGNORE
		CASE lRetry
			nTypeIconButton := MB_RETRYCANCEL
		OTHER
			nTypeIconButton := MB_OK
	ENDCASE
	nTypeIconButton+=MB_ICONERROR + MB_SYSTEMMODAL
	nRetMsg:=MessageBoxTimeout ( ErrorMesssage , 'Program Error ' , nTypeIconButton, nMilliseconds)
	
	DO CASE
		CASE nRetMsg=IDRETRY .OR. nRetMsg=IDTRYAGAIN
			RETURN (.T.)
		CASE nRetMsg=IDIGNORE 
			RETURN (.F.)
		OTHER
			// "Quit" selected
			UnloadAllDll()
			dbcloseall()
			ExitProcess(0)
			QUIT
	ENDCASE

Return .F.
*************************************************************************************************
STATIC FUNCTION ErrorMessage( oError )
   LOCAL cMessage

   // start error message
   cMessage := iif( oError:severity > ES_WARNING, "Error", "Warning" ) + " "

   // add subsystem name if available
   IF ISCHARACTER( oError:subsystem )
      cMessage += oError:subsystem()
   ELSE
      cMessage += "???"
   ENDIF

   // add subsystem's error code if available
   IF ISNUMBER( oError:subCode )
      cMessage += "/" + LTRIM( STR( oError:subCode ) )
   ELSE
      cMessage += "/???"
   ENDIF

   // add error description if available
   IF ISCHARACTER( oError:description )
      cMessage += "  " + oError:description
   ENDIF

   // add either filename or operation
   DO CASE
   CASE !Empty( oError:filename )
      cMessage += ": " + oError:filename
   CASE !Empty( oError:operation )
      cMessage += ": " + oError:operation
   ENDCASE

   RETURN cMessage
Edward.
Locutio est argentum, silentium est aureum

User avatar
serge_girard
Posts: 1627
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 185 times
Been thanked: 29 times
Contact:

Post by serge_girard » Tue Feb 07, 2017 11:27 am

Why is UnloadAllDll() needed and what does it do?
In all my errorsys.prg's there is no UnloadAllDll()...
Should I include it?

Serge

franco
Posts: 134
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 1 time

Post by franco » Tue Feb 07, 2017 5:44 pm

After I modify Errorsys.prg .............. to rebuild do I run buildalllib.bat
Would the francoerror sample work for complete error function for my program.
I have a procedure program would I put all in there .
I do not know what a static function is. Does it mean always available. If so in my procedure program would it need to be static.
Franco

User avatar
mol
Posts: 2671
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 72 times
Been thanked: 24 times
Contact:

Post by mol » Tue Feb 07, 2017 5:54 pm

Static function works only in module, where it's defined

franco
Posts: 134
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 1 time

Post by franco » Mon Feb 13, 2017 5:36 pm

After I modified Errorsys.prg .............. and run buildalllib.bat, I have had no more black screens. This was originally very random.
We will stay posted.
Thanks to all and Mol your responses were very helpful.
It is a joy to be associated with such great knowledge.
Franco

User avatar
mol
Posts: 2671
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 72 times
Been thanked: 24 times
Contact:

Post by mol » Mon Feb 13, 2017 7:10 pm

Thanks belong to Edward!

User avatar
Pablo César
Posts: 4010
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 99 times
Been thanked: 159 times

Post by Pablo César » Mon Feb 13, 2017 7:14 pm

mol wrote:
Mon Feb 13, 2017 7:10 pm
Thanks belong to Edward!
Thank you both. Good fixing Edward.

I think this could be patched to HMG core. Is it possible, Is feasible Claudio/Rathi ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest