Error in Virtual Grid with dynamic font

Moderator: Rathinagiri

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

Error in Virtual Grid with dynamic font

Post by mol » Fri May 10, 2019 6:47 am

I found wrong behavior of GRID control when DynamicFont is used.
I want to use editable virtual grid with last column displayed with different font.
Everything goes OK with displaying.
When I edit cell and want to save it in array, This.CellColIndex always returns index of column dynamic font (in my sample last column, but you can test it with another)

Code: Select all

#include "hmg.ch"

Function Main
	public aCellCoordinates := {0,0}
	private aItems := {}

	AADD (aItems, {"Carrot",        5, "A"})
	AADD (aItems, {"Cauliflower",   0, "B"})
	AADD (aItems, {"Corn",         15, "C"})
	AADD (aItems, {"Tomato",        0, "D"})
	AADD (aItems, {"Zucchini",     20, "E"})

	aControls := { NIL, {'TEXTBOX','NUMERIC'}, NIL }
	aValid	:= { {||Grid_1_Valid()}, {||Grid_1_Valid()}, {||Grid_1_Valid()} }
	aWhen	:= { {||Grid_1_When()}, {||Grid_1_When()}, {||Grid_1_When()} }
	aJustify := {  GRID_JTFY_LEFT, GRID_JTFY_RIGHT, GRID_JTFY_CENTER }
   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 600 ;
      HEIGHT 400 ;
      MAIN 

	DEFINE GRID Grid_1
		PARENT Form_1
		ROW 10
		COL 10
		WIDTH 550
		HEIGHT 330
		ITEMS NIL
		HEADERS {'Product','Stock','Supplier'}
		FONTNAME "ARIAL"
		FONTSIZE 12
		WIDTHS {250,150,100}
		ALLOWEDIT .T.
		CELLNAVIGATION .T.
		COLUMNCONTROLS aControls
		COLUMNVALID aValid
		COLUMNWHEN aWhen
		VIRTUAL .T.
		OnQueryData Grid_1_OnQueryData()
		ITEMCOUNT len(aItems)
	END GRID
	
	aFont := ARRAY FONT "Webdings" SIZE 12 BOLD ITALIC
	if MsgYesNo("Do you want to test with Dynamic Font?")
		Form_1.Grid_1.ColumnDYNAMICFONT  (3) := {|| IF ( Form_1.Grid_1.CellEx(This.CellRowIndex,2) == 0, aFont, NIL) }
	endif

   END WINDOW

   CENTER WINDOW Form_1
   ACTIVATE WINDOW Form_1

Return
*--------------------------------
function Grid_1_OnQueryData

	local nRow
	local nCol

	nRow := This.QueryRowIndex
	nCol := This.QueryColIndex

	if nRow>0 .and. nCol >0
		This.QueryData := aItems[nRow, nCol]
	endif
return
*--------------------------------
function Grid_1_Valid
	local nRow
	local nCol

	nRow := This.CellRowIndex
	nCol := This.CellColIndex
	MsgInfo( "Coordinates saved in VALID function: " + hb_valtoexp(aCellCoordinates)+chr(10)+;
		"Actual coordinates: "+hb_valtoexp({nRow, nCol}) )
	aItems[nRow, nCol ] := This.CellValue
 return .t.
*--------------------------------
function Grid_1_When
	
	aCellCoordinates := { This.CellRowIndex, This.CellColIndex }
return .T.
*--------------------------------


User avatar
andyglezl
Posts: 1151
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 35 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri May 10, 2019 5:13 pm

Yo veo que si se está grabando en el ARRAY lo que hay en el GRID...(o tal vez no entendí tu pregunta)
*-----------------------------------------------------------------------------------------------------------------------------
I see that if you are recording in the ARRAY what is in the GRID ... (or maybe I did not understand your question)


mol.png
mol.png (46.9 KiB) Viewed 781 times
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
andyglezl
Posts: 1151
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 35 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri May 10, 2019 5:35 pm

OK ya vi el problema
*-----------------------------------
OK I saw the problem
mol.png
mol.png (56.38 KiB) Viewed 777 times
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
andyglezl
Posts: 1151
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 35 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri May 10, 2019 6:05 pm

Si cambias lo siguiente, funciona OK
*----------------------------------------------------
If you change the following, it works OK

Code: Select all

*--------------------------------
function Grid_1_Valid
	local nRow
	local nCol

	*nRow := This.CellRowIndex
	*nCol := This.CellColIndex
	
	nRow := aCellCoordinates[ 1 ]
	nCol := aCellCoordinates[ 2 ]
	
	MsgInfo( "Coordinates saved in VALID function: " + hb_valtoexp(aCellCoordinates)+chr(10)+;
		"Actual coordinates: "+hb_valtoexp({nRow, nCol}) )
	aItems[nRow, nCol ] := This.CellValue
	MSGDEBUG( aItems )
 return .t.
mol.png
mol.png (66.55 KiB) Viewed 773 times
Andrés González López
Desde Guadalajara, Jalisco. México.

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

Post by mol » Fri May 10, 2019 9:22 pm

Of course we can use workaround, but this situation is a bug and should be repaired in sources.
I've lost a lot of time to find what's going on

User avatar
andyglezl
Posts: 1151
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 35 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri May 10, 2019 9:40 pm

Lo siento, yo nunca he modificado algún fuente de HMG...
*----------------------------------------------------------------------------
I'm sorry, I've never modified any source of HMG ...

A quien corresponda:
*---------------------------
To whom it May concern:
mol wrote:
Fri May 10, 2019 9:22 pm
Of course we can use workaround, but this situation is a bug and should be repaired in sources.
I've lost a lot of time to find what's going on
Andrés González López
Desde Guadalajara, Jalisco. México.

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

Post by mol » Tue Jun 11, 2019 7:55 pm

I found another strange behavior of GRID control.
When I'm editing cell with defined WHEN, when function is called for every cell in row - it causes strange flickering, etc...
I'll prepare small sample or video.
While investigating this, I found the problem is within PROCEDURE _HMG_GRIDINPLACEKBDEDIT_2(i) in h_grid.prg lines 1957-2035:

Code: Select all

If ValType ( aColumnWhen ) == 'A'

                  nStart := _HMG_SYSDATA [ 15 ] [I]
   
                  nEnd := HMG_LEN ( aColumnWhen )

                  For j := nStart To nEnd

                     If ValType ( aColumnWhen [j] ) == 'B'

*******************************************************************************************************************************
                        IF _HMG_SYSDATA [ 40 ] [ i ] [ 9 ] == .F.
                           aTemp := this.item( nWhenRow )
                           xTmpCellValue := aTemp [j]
                        ELSE
                           _HMG_SYSDATA [ 201 ] := nWhenRow // QueryRowIndex
                           _HMG_SYSDATA [ 202 ] := j   // QueryColIndex
                           _HMG_SYSDATA [ 320 ] := .T.
                           IF ValType ( _HMG_SYSDATA [ 40 ] [ i ] [ 10 ] ) == 'C'
                              GetDataGridCellData ( i , .t. )
                           ELSE
                              Eval( _HMG_SYSDATA [  6 ] [ i ]  )      
                           ENDIF
                           _HMG_SYSDATA [ 320 ] := .F.
                           xTmpCellValue := _HMG_SYSDATA [ 230 ]   
                        ENDIF
********************************************************************************************************************************

                        _HMG_SYSDATA [ 318 ] := xTmpCellValue

                        _HMG_SYSDATA [ 232 ] := 'GRID_WHEN'

                        lResult := Eval ( aColumnWhen [j] )

                        _HMG_SYSDATA [ 232 ] := ''

                        If lResult == .F.

                           _HMG_SYSDATA [ 15 ] [I]++
                        
                        Else

                           Exit

                        EndIf

                     EndIf

                  Next j
Setting nEnd to HMG_LEN ( aColumnWhen ) causes testing every cell to the end of row - why?!
In my opinion it should be tested only current cell.

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

Post by serge_girard » Wed Jun 12, 2019 9:26 am

Marek,

I'm afraid that as long as we have no successor for Claudio, we will have to work with this kind of work-arounds...
Regretfully, but I don't see any other option...

Serge

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

Post by mol » Wed Jun 12, 2019 8:11 pm

You are right, Serge!
It's very sad.
Our hmg is going to dead.
It is dangerous to have only one leader

User avatar
apais
Posts: 309
Joined: Fri Aug 01, 2008 6:03 pm
Location: uruguay
Has thanked: 50 times
Been thanked: 28 times
Contact:

Post by apais » Thu Jun 13, 2019 12:07 am

That's why I've been suggesting the merge among HMG and HMG Extended.
HMG Extended has a better development pace, and Harbour has a better forum/community.

Post Reply